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: ...
随机推荐
- laravel中生成支付宝 二维码 扫码支付
文档教程模拟: http://www.023xs.cn/Article/37/laravel5%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9Dalipay%E ...
- 【翻译】HTML5开发——轻量级Web Database存储库html5sql.js
方式1: html5sql官方网址:http://html5sql.com/ 阅读之前,先看W3C关于WEB Database的一段话: Beware. This specification is n ...
- Java集合类综合
Java集合类是JDK学习中的一个经典切入点,也是让初学者最初感受到Java魅力的地方之一,你一定不会忘记不需要关心大小的ArrayList,不用自己实现的Queue,和随处可见的HashMap.面试 ...
- HDU 1043 八数码问题的多种解法
一.思路很简单,搜索.对于每一种状态,利用康托展开编码成一个整数.于是,状态就可以记忆了. 二.在搜索之前,可以先做个优化,对于逆序数为奇数的序列,一定无解. 三.搜索方法有很多. 1.最普通的:深搜 ...
- JAVA中方法和变量在继承中的覆盖和隐藏(一)
我们知道,在JAVA中,子类可以继承父类,如果子类声明的方法与父类有重名的情况怎么办,大伙儿都知道要是重写,但是实际上这又分为两种情况,就是方法和变量在继承时的覆盖和隐藏问题,这些概念性的东西看似无聊 ...
- Tomcat中部署网站和绑定域名
在安装的tomcat的文件夹下有个conf文件夹 下面有个server.xml文件, 1. 使用80端口 默认tomcat用的是8080端口. <Connector port="808 ...
- 关于diskgenius删除所有分区后,电脑不能识别U盘的问题。
楼主曾今为了将Linux系统安装至U盘中,曾无数次对U盘进行过格式化,到最后导致,u盘各种引导.系统.烂数据存在U盘,导致U盘的使用越来越不方便.后来终于下狠心,利用diskgenius对U盘进行一次 ...
- 实战zabbix3.0.2 使用percona mysql插件监控mysql5.7
1.系统环境 [root@shard0 templates]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.2 ...
- Linux TCP/IP 连接查看和问题解决
netstat -nat|awk '{print awk $NF}'|sort|uniq -c|sort -n 上面的 命令可以帮助分析哪种Tcp状态数量异常 netstat -nat|gr ...
- C#泛型序列化困境
[C#泛型序列化困境] 问题的起因是这样,有一个需求,将JsonArray转化为List,JsonArray中的元素均是string,此string可被转化为int.float.或维持string.我 ...