Density of Power Network(ZOJ 3708)
Problem
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
题解:大体意思就是给你一些公交站牌和一些公交路线,定义一个密度,是路线的条数 / 公交站牌的个数。第一行是公交初始的
位置,下面一行对应的是末位置。如果路线一样去重一下就可以了。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
using namespace std;
int vis[550][550];
int a[550],b[550];
int main()
{
int t,n,i,j,m,w;
double ans;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=1; i<=m; i++)
scanf("%d",&a[i]);
for(i=1; i<=m; i++)
scanf("%d",&b[i]);
memset(vis,0,sizeof(vis));
w = 0;
for(i=1; i<=m; i++)
{
if(vis[a[i]][b[i]] == 0)
{
vis[a[i]][b[i]] = 1;
vis[b[i]][a[i]] = 1;
w++;
}
}
// cout<<w<<" "<<n<<endl;
ans = (double)w/(double)n;
printf("%.3lf\n",ans);
}
return 0;
}
Density of Power Network(ZOJ 3708)的更多相关文章
- POJ - 1459 Power Network(最大流)(模板)
1.看了好久,囧. n个节点,np个源点,nc个汇点,m条边(对应代码中即节点u 到节点v 的最大流量为z) 求所有汇点的最大流. 2.多个源点,多个汇点的最大流. 建立一个超级源点.一个超级汇点,然 ...
- POJ-1459 Power Network(最大流)
https://vjudge.net/problem/POJ-1459 题解转载自:優YoU http://user.qzone.qq.com/289065406/blog/1299339754 解题 ...
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- [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 ...
- Power Network(网络流最大流 & dinic算法 + 优化)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24019 Accepted: 12540 D ...
- POJ1459 Power Network(网络最大流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total S ...
- Power Network (最大流增广路算法模板题)
Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 20754 Accepted: 10872 Description A p ...
- 2018.07.06 POJ 1459 Power Network(多源多汇最大流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...
随机推荐
- (一)CXF之发布第一个WebService服务
一.CXF入门 1.1 前提 Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS .这些 ...
- C语言数组不知道输入几个整数以及输入一直到为0
输入一直到为0: ){ } 数组不知道输入几个整数: ],num=; for(;;num++){ scanf("%d",&array[num]); if(getchar() ...
- Sublime Text 添加java环境
jre/bin/ 目录下添加 runJava.bat @ECHO OFF cd %~dp1 ECHO Compiling %~nx1....... IF EXIST %~n1.class ( DEL ...
- IOC实现-Unity
.NET中实现IOC有很多方式,比如:Unity.Ninject.Autofac.MEFNinject的实现参考<Pro ASP.NET MVC3.5 FrameWork>下面给出的是Un ...
- VisualSVN 关于权限(第1篇)
总结权限的规则: 1.子目录权限完全覆盖父目录权限.以子目录的权限为最终.仓库本身就是祖宗,所有的子目录继承他的权限,所有仓库本身必须增加可访问权限,要么everyone ,要么增加全部团队成员. 2 ...
- 报错/Warning: You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored
这个报错在以下情形会出现 第一种 <Switch> <Route exact path="/home/index" component={HomeIndex} / ...
- js的页面交互
与html标签建立关系 //获取标签,js如何与html标签建立联系 两种方式 //1. let num = document.getElementsByClassName('d1'); consol ...
- Vivado Bit文件压缩
前言 Vivado编译生成的Bit文件太大,想要小一点该咋办呢?那么就需要给bit文件瘦身. 流程 直接在约束文件xdc中添加下述语句即可: set_property BITSTREAM.GENERA ...
- dockerfile构建nginx
mkdir docker_demo cd docker_demo wget http://nginx.org/download/nginx-1.2.9.tar.gz vim Dockerfile FR ...
- js 面试题一
1.格式化数字,每三位加逗号 // 实现方式一 function formatNum(num){ var _num = num + ""; var result = "& ...