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: ...
随机推荐
- ajax readyState=4并且status=200时,还进error方法
今天在使用jQuery.ajax方法去调用后台方法时,ajax中得参数data类型是"JSON",后台DEBUG调试,运行正常, 返回正常的结果集,但是前端一直都进到ajax的er ...
- 黄聪:WordPress 多站点建站教程(四):获取子站点相关信息(站点的注册时间,修改时间,总文章数,URL等)
1.获取子站点blogs表里面的内容信息 $blog_details = get_blog_details(1); echo 'Blog '.$blog_details->blog_id.' i ...
- 生成式对抗网络(GAN)
生成对抗网络(GAN),是深度学习模型之一,2014年lan Goodfellow的开篇之作Generative Adversarial Network, GAN概述 GAN包括两个模型,一个是生成模 ...
- 认识Linux操作系统
Linux系统是一个类似UNIX的操作系统 认识Linux的来世与今生 1.Linux系统的历史 Linux系统是一个类似UNIX的操作系统,Linux系统是UNIX在微机上的完整实现,它的标志是一个 ...
- 源文件封装为IP的步骤
因为模块的交接,最好将写好的源文件和生成的IP封装一个IP,然后再转交给其他的同事使用,这是一种好的习惯.但是对于,封装的过程还是需要注意一下.实际的看看步骤吧.1)将源文件和使用到的IP生成工程. ...
- thymeleaf 之 th:each迭代循环对象集合
thymeleaf 之 th:each迭代循环对象集合 2018年02月24日 14:32:31 阅读数:1382 th:each属性用于迭代循环,语法:th:each="obj,iterS ...
- PyQt5系列教程(二)利用QtDesigner设计UI界面
软硬件环境 OS X EI Capitan Python 3.5.1 PyQt 5.5.1 PyCharm 5.0.1 前言 在PyQt5系列教程的第一篇http://blog.csdn.net/dj ...
- jsp 学习 第1步 - 引入 jstl
通过 eclipse 新建 动态web项目 默认是没有引入 jstl, 则无法JSP页面引入相关标记. <%@ taglib prefix="c" uri="ht ...
- padding margin border 和元素大小
元素占用宽度 = 元素宽度+padding+border+margin 注意margin只是隔开元素,不会使得元素变大,而padding会使得元素变大,也就是说 元素真实宽度=元素宽度+padding ...
- ArrayList原理(一)
需要使用到动态数组的时候用的最多的就是ArrayList了,底层其实是Object数组,以下demo基于JDK1.8: List<Integer> list = new ArrayLis ...