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 ...
 
随机推荐
- ajax  post上传数据时,前端出现的跨域权限问题:ccess to XMLHttpRequest at ‘’rom origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok st
			
本人前端使用多个框架时,jq ajax传参出现如下报错: 最后发现,可能是xhr的相关默认参数被修改了.顾使用jq 传参时,一直报错,jq ajax额外添加的关键参数: crossDomain: ...
 - 在oracle表中增加、修改、删除字段,表的重命名,字段顺序调整
			
增加字段语法:alter table tablename add (column datatype [default value][null/not null],….); 说明:alter table ...
 - AtCoder练习
			
1. 3721 Smuggling Marbles 大意: 给定$n+1$节点树, $0$为根节点, 初始在一些节点放一个石子, 然后按顺序进行如下操作. 若$0$节点有石子, 则移入盒子 所有石子移 ...
 - Apache2.4+Tomcat7.0+php5.5整合配置详解
			
在上一篇的基础上,继续添加php的配置 一.首先下载php5.5 首先下载php5.5,到官网下载http://www.php.net/downloads.php,参考http://www.cnblo ...
 - C# DataTable和List转换操作类
			
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.R ...
 - android 仿微信朋友圈图片选择控件
			
调用方式(布局文件就是一个自定义控件): private ArrayList<String> selectedImages; @BindView(R.id.imagePicker) Ima ...
 - ASP.NET Core 入门(1)(搭建环境CentOS)
			
一.CentOS 7 安装 下载CentOS http://isoredirect.centos.org/centos/7/isos/x86_64/ 选择其中下载即可. 下载完成后打开vmware准 ...
 - Python UDP 通信
			
UDP_Client.py import socket # 创建一个 UDP 套接字 udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DG ...
 - flask   反向解析示例
			
1 静态网页 和动态网页 1 静态网页:无法与服务器做动态交互的网页 2 动态网页:允许与服务器做动态加护的 2 WEB 与 服务器 1 WEB :网页(HTML,css,JS) 3 服务器的作用: ...
 - JavaScript程序块初始练习
			
由语句语句块,函数,对象,方法,属性构成.通过顺序,分支,循环三种基本程序控制结构来进行编程. 来一段小代码: <!DOCTYPE html> <html> <head& ...