[ACM_图论] 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 ≤ NM ≤ 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 }
复制代码
相关文章
|
6月前
|
机器学习/深度学习 算法 数据挖掘
Hybrid-SORT起飞 | 超过DeepSORT将近10个点的多目标跟踪香不香?
Hybrid-SORT起飞 | 超过DeepSORT将近10个点的多目标跟踪香不香?
181 0
|
编解码
猪笼草表面连续定向输水Continuous directional water transport on the peristome surface of Nepenthes alata-2016-阅读笔记
打破了传统水往下流的思路,仿生猪笼草表面结构,提出定向水传输结构。
ICPC North Central NA Contest 2018 G . Tima goes to Xentopia(最短路 空间优化 剪枝)
ICPC North Central NA Contest 2018 G . Tima goes to Xentopia(最短路 空间优化 剪枝)
75 0
luoguP2205 [USACO13JAN]Painting the Fence S(差分 扫描线思想)
luoguP2205 [USACO13JAN]Painting the Fence S(差分 扫描线思想)
59 0
[North Central NA Contest 2018] Rational Ratio | 规律 细节模拟
Description Every (positive) rational number can be expressed as a ratio of two (positive) integers. However, in decimal form, rational numbers often have an infifinitely repeating pattern, e.g., 1/7 = 0.142857142857142857…
107 0
[North Central NA Contest 2018] Rational Ratio | 规律 细节模拟
[UVA1364 | POJ | NC]Knights of the Round Table | Tarjan 求点双 | 二分图 | 综合图论
我们可以很轻松地发现,被提出的都是在点双连通分量之外的,比如该图中的1 和 5 ,那么怎么判断哪些点不在环中呢? 此时我们还可以逆向思考,不 在 环 中 的 = = 总 的 − 在 环 中 的,所以说现在问题就转换成了满足条件的环内的点的个数
128 0
[UVA1364 | POJ | NC]Knights of the Round Table | Tarjan 求点双 | 二分图 | 综合图论
[USACO | UPC] Liars and Truth Tellers | 拓展域并查集
题目描述 After spending so much time around his cows, Farmer John has started to understand their language. Moreover, he notices that among his N cows (2 ≤ N ≤ 1000 ), some always tell the truth while others always lie.
128 0
峰识别 峰面积计算 peak detection peak area 源代码 下载
原文:峰识别 峰面积计算 peak detection peak area 源代码 下载 Comparative  analysis  of  peak-detection  techniques  ...
1106 0