题意:有n个bus,m个线路,求线路除上bus的值...注意重复...
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.500 1.429
#include <stdio.h>
#include <string.h>
struct node
{
int x,y;
}a[510];
int main()
{
int f[510][510],i,n,m,T;
scanf("%d",&T);
while (T--)
{
int s=0;
scanf("%d%d",&n,&m);
for (i=1;i<=m;i++)
scanf("%d",&a[i].x);
for (i=1;i<=m;i++)
scanf("%d",&a[i].y);
memset(f,0,sizeof(f));
for (i=1;i<=m;i++)
if((!f[a[i].x][a[i].y]) && (!f[a[i].y][a[i].x]))
{
s++;
f[a[i].x][a[i].y]=f[a[i].y][a[i].x]=1;
}
printf("%.3lf\n",s*1.0/n);
}
return 0;
}
电力系统网络密度计算
本文介绍了一种计算电力系统网络密度的方法,通过分析传输线路与变电站的数量比来评估系统的健壮性。考虑到实际系统中可能存在的冗余线路,算法确保了每一对连接的变电站仅被计算一次。
2483

被折叠的 条评论
为什么被折叠?



