Skip to content

Commit

Permalink
e200: Add server broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Sep 18, 2024
1 parent 91c47b1 commit 41a75ae
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,6 @@
- [周末爬山 - DFS](od/2024e200/climb-mountain/index.md)
- [计算网络信号/信号强度 - BFS](od/2024e200/signal-intensity/index.md)
- [九宫格按键输入](od/2024e200/speed-dial-input/index.md)
- [服务器广播/需要广播的服务器数量 - 并查集](od/2024e200/server-broadcast/index.md)

[参考资料](refs.md)
3 changes: 2 additions & 1 deletion src/od/2024e200/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
26. [电脑病毒感染 - 图](computer-virus/index.md)
27. [周末爬山 - DFS](climb-mountain/index.md)
28. [计算网络信号/信号强度 - BFS](signal-intensity/index.md)
29. [九宫格按键输入](speed-dial-input/index.md)
29. [九宫格按键输入](speed-dial-input/index.md)
30. [服务器广播/需要广播的服务器数量 - 并查集](server-broadcast/index.md)
7 changes: 7 additions & 0 deletions src/od/2024e200/server-broadcast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "e200-server-broadcast"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
3 changes: 3 additions & 0 deletions src/od/2024e200/server-broadcast/assets/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 0 0
0 1 0
0 0 1
2 changes: 2 additions & 0 deletions src/od/2024e200/server-broadcast/assets/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 1
1 1
1 change: 1 addition & 0 deletions src/od/2024e200/server-broadcast/assets/output1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions src/od/2024e200/server-broadcast/assets/output2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
61 changes: 61 additions & 0 deletions src/od/2024e200/server-broadcast/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 服务器广播/需要广播的服务器数量

## 题目描述

服务器连接方式包括直接相连, 间接连接.

A和B直接连接, B和C直接连接, 则A和C间接连接.

直接连接和间接连接都可以发送广播.

给出一个N*N数组, 代表N个服务器.

matrix[i][j] == 1, 则代表i和j直接连接; 不等于 1 时, 代表i和j不直接连接.

matrix[i][i] == 1, 即自己和自己直接连接. matrix[i][j] == matrix[j][i].

计算初始需要给几台服务器广播, 才可以使每个服务器都收到广播.

### 输入描述

输入为N行, 每行有N个数字, 为0或1, 由空格分隔,

构成N*N的数组, N的范围为 1 <= N <= 40.

### 输出描述

输出一个数字, 为需要广播的服务器的数量.

### 示例1

输入:

```text
{{#include assets/input1.txt}}
```

输出:

```text
{{#include assets/output1.txt}}
```

说明: 3 台服务器互不连接, 所以需要分别广播这 3 台服务器.

### 示例2

输入:

```text
{{#include assets/input2.txt}}
```

输出:

```text
{{#include assets/output2.txt}}
```

说明: 2 台服务器相互连接, 所以只需要广播其中一台服务器.

## 题解
3 changes: 3 additions & 0 deletions src/od/2024e200/server-broadcast/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit 41a75ae

Please sign in to comment.