ZOJ 3708 [Density of Power Network 线路密度,a->b=b->a去重]
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
Author: WANG,
Yelei
Contest: The 10th Zhejiang
Provincial Collegiate Programming Contest
题目大意:每个样例第一行是公交车的数目与路线的数目,第二行是公交车起点,第三行是终点,从a->b与b->a是同一条路线,计算总路线与车辆数目的比值
解题思路:水题,不解释。
1 #include<iostream> 2 #include<algorithm> 3 #include<string.h> 4 #include<stdio.h> 5 #include<set> 6 using namespace std; 7 int main(){ 8 int T; 9 cin>>T; 10 while(T--){ 11 int N,M; 12 cin>>N>>M; 13 int start[505],end[505]; 14 for(int i=0;i<M;i++) 15 cin>>start[i]; 16 for(int i=0;i<M;i++) 17 cin>>end[i]; 18 19 int curM=M; 20 for(int i=0;i<M-1;i++){ 21 for(int j=i+1;j<M;j++){ 22 if((start[i]==start[j] && end[i]==end[j]) 23 ||(start[i]==end[j] && end[i]==start[j])){ 24 curM--; 25 break; 26 } 27 } 28 } 29 30 printf("%.3lf\n",curM/(1.0*N)); 31 }return 0; 32 33 }
ZOJ 3708 [Density of Power Network 线路密度,a->b=b->a去重],古老的榕树,5-wow.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。