ZOJ3708:Density of Power Network
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
题意:每个样例第一行是公交车的数目与路线的数目,第二行是公交车起点,第三行是终点,从a->b与b->a是同一条路线,计算总路线与车辆数目的比值
#include <stdio.h>
#include <string.h> int s[505][505]; int main()
{
int n,m,i,j,sum,a[505],b[505];
double ans;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(s,0,sizeof(s));
sum = 0;
for(i = 1; i<=m; i++)
scanf("%d",&a[i]);
for(i = 1; i<=m; i++)
scanf("%d",&b[i]);
for(i = 1; i<=m; i++)
{
if(!s[a[i]][b[i]])
sum++;
s[a[i]][b[i]] = s[b[i]][a[i]] = 1;
}
printf("%.3lf\n",(double)sum/n);
}
return 0;
}
ZOJ3708:Density of Power Network的更多相关文章
- [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 innovatio ...
- Density of Power Network(ZOJ 3708)
Problem The vast power system is the most complicated man-made system and the greatest engineering i ...
- zoj 3708 Density of Power Network
/*看英文和图我头都大了,不过很简单的.*/ #include<string.h> #include<stdio.h> ][],q[],w[]; int main(int ar ...
- ZOJ Problem Set - 3708 Density of Power Network
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3708 #include <stdio.h> #include ...
- poj1459 Power Network (多源多汇最大流)
Description A power network consists of nodes (power stations, consumers and dispatchers) connected ...
- Power Network(网络流最大流 & dinic算法 + 优化)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24019 Accepted: 12540 D ...
- Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...
- POJ1459 Power Network(网络最大流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total S ...
- poj 1459 Power Network : 最大网络流 dinic算法实现
点击打开链接 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 20903 Accepted: ...
随机推荐
- TextRank in Python
运用到nltk,sklearn,networkx等很多好用的库,值得参考 https://joshbohde.com/blog/document-summarization
- ASP.NET 获得当前网页名字
Code string currentFilePath = HttpContext.Current.Request.FilePath; string CurrentPageName = current ...
- eaccelerator详解
之前在看书的时候看到一个eaccelerator,以前也没用过 不知道是啥东东,不知道以后会用到不,先mark一下吧 eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了 ...
- migrating-vcenter-database-express-to-sql-2008-r2
migrating-vcenter-database-express-to-sql-2008-r2 一. 准备环境. ESXi5.0主机 IP:192.168.1.158 ...
- js 按字段分组
var data = [{"id":"32b80b76-a81e-4545-8065-1e7c57180801","userId":&quo ...
- C语言指针的一些题目
1.将从键盘输入的每个单词的第一个字母转换成大写字母输入时各单词以空格隔开,用“.”结束输入 解体思路: 把输入的字符存入字符数组中直到输入".",然后调用函数,把字符串的第一个 ...
- uva-11234-表达式
后缀表达式,使用队列计算,要求计算的结果一样,输出队列的输入串 表达式转二叉树,层次序遍历,先右孩子,然后字符串反转输出 #include <iostream> #include < ...
- OpenMP 《并行程序设计导论》的补充代码
▶ 使用 OpenMP 和队列数据结构,在各线程之间传递信息 ● 代码,使用 critical 子句和 atomic 指令来进行读写保护 // queue.h #ifndef _QUEUE_H_ #d ...
- 取消Eclipse的Error Reporting
选择Preferences->General->Error Reporting,Send Mode选择Never send reports
- 【独家】阿里天池IJCAI17大赛第四名方案全解析(附代码)
[独家]阿里天池IJCAI17大赛第四名方案全解析(附代码) https://mp.weixin.qq.com/s?__biz=MzAxMzA2MDYxMw==&mid=2651560625& ...