ZOJ 3708 Density of Power Network
2016-04-12 23:25
323 查看
Description
The vast power system is the most complicated man-made system and the greatest engineering innovation in the 20th century. The following diagram shows a typical 14 bus power system. In real world, the power system may contains hundreds of buses and thousands
of transmission lines.
Network topology analysis had long been a hot topic in the research of power system. And network density is one key index representing the robustness of power system. And you are asked to implement a procedure to calculate the network density of power system.
The network density is defined as the ratio between number of transmission lines and the number of buses. Please note that if two or more transmission lines connecting the same pair of buses, only one would be counted in the topology analysis.
Input
The first line contains a single integer T (T ≤ 1000), indicating there are T cases in total.
Each case begins with two integers N and M (2 ≤ N, M ≤ 500) in the first line, representing the number of buses and the number of transmission lines in the power system. Each Bus would be numbered from 1 to N.
The second line contains the list of start bus number of the transmission lines, separated by spaces.
The third line contains the list of corresponding end bus number of the transmission lines, separated by spaces. The end bus number of the transmission lines would not be the same as the start bus number.
Output
Output the network density of the power system in a single line, as defined in above. The answer should round to 3 digits after decimal point.
Sample Input
Sample Output
看题目好像很复杂,其实就是个水题,计算有几条重边即可。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 5e2 + 10;
int T, n, m;
int a[maxn], b[maxn];
int vis[maxn][maxn];
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n,&m);
for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
memset(vis, 0, sizeof(vis));
int cnt = m;
for (int i = 1; i <= m; i++)
{
if (a[i] > b[i]) swap(a[i], b[i]);
if (vis[a[i]][b[i]]) cnt--; else vis[a[i]][b[i]] = 1;
}
printf("%.3lf\n", 1.0*cnt / n);
}
return 0;
}
The vast power system is the most complicated man-made system and the greatest engineering innovation in the 20th century. The following diagram shows a typical 14 bus power system. In real world, the power system may contains hundreds of buses and thousands
of transmission lines.
Network topology analysis had long been a hot topic in the research of power system. And network density is one key index representing the robustness of power system. And you are asked to implement a procedure to calculate the network density of power system.
The network density is defined as the ratio between number of transmission lines and the number of buses. Please note that if two or more transmission lines connecting the same pair of buses, only one would be counted in the topology analysis.
Input
The first line contains a single integer T (T ≤ 1000), indicating there are T cases in total.
Each case begins with two integers N and M (2 ≤ N, M ≤ 500) in the first line, representing the number of buses and the number of transmission lines in the power system. Each Bus would be numbered from 1 to N.
The second line contains the list of start bus number of the transmission lines, separated by spaces.
The third line contains the list of corresponding end bus number of the transmission lines, separated by spaces. The end bus number of the transmission lines would not be the same as the start bus number.
Output
Output the network density of the power system in a single line, as defined in above. The answer should round to 3 digits after decimal point.
Sample Input
3 3 2 1 2 2 3 2 2 1 2 2 1 14 20 2 5 3 4 5 4 5 7 9 6 11 12 13 8 9 10 14 11 13 13 1 1 2 2 2 3 4 4 4 5 6 6 6 7 7 9 9 10 12 14
Sample Output
0.667 0.5001.429
看题目好像很复杂,其实就是个水题,计算有几条重边即可。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 5e2 + 10;
int T, n, m;
int a[maxn], b[maxn];
int vis[maxn][maxn];
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n,&m);
for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
memset(vis, 0, sizeof(vis));
int cnt = m;
for (int i = 1; i <= m; i++)
{
if (a[i] > b[i]) swap(a[i], b[i]);
if (vis[a[i]][b[i]]) cnt--; else vis[a[i]][b[i]] = 1;
}
printf("%.3lf\n", 1.0*cnt / n);
}
return 0;
}
相关文章推荐
- zoj3549 快速幂
- ZOJ 1002
- ZOJ-3861 DFS+回溯
- ZOJ3279 —— 8G island
- zoj_1004-Anagrams by stack
- zoj_2278-Fight for Food
- ZOJ 1001 A+B Problem
- zoj 2710 Two Pipelines
- zoj 386 4000 1 Valid Pattern Lock
- ZOJ 3755 Mines 回溯+剪枝
- ZOJ3750 Dot Dot Dot 枚举状态+BFS
- poj 1514&zoj 1185 Metal Cutting(半平面交)
- ZOJ1101-Gamblers 终于AC。。。
- zoj 1148 The Game 一个晚上终于AC!
- zoj 3420 纯bfs
- PAT 01-复杂度2. Maximum Subsequence Sum (25)&&PAT 01-复杂度1. 最大子列和问题(20)
- 狗狗40题~ (Volume A)
- 狗狗40题~ (Volume B)
- 狗狗40题~ (Volume C)
- ZOJ3319 DP 通过入度出度判非法情况