2014ACM集训13级PK赛3-Density of Power Network
来源:互联网 发布:淘宝上的win10激活码 编辑:程序博客网 时间:2024/05/16 04:47
Description
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
33 21 22 32 21 22 114 202 5 3 4 5 4 5 7 9 6 11 12 13 8 9 10 14 11 13 131 1 2 2 2 3 4 4 4 5 6 6 6 7 7 9 9 10 12 14
Sample Output
0.6670.5001.429
图
#include <stdio.h>#include <string.h>#include <stdlib.h>int qi[1000],zhong[1000];int imap[1010][1010];int main(){ int N; scanf ("%d",&N); while (N--) { memset(imap,0,sizeof (imap)); int n,m; int i; scanf ("%d%d",&n,&m); for (i = 0;i < m;i++) scanf ("%d",&qi[i]); for (i = 0;i < m;i++) scanf ("%d",&zhong[i]); int sum = 0; for (i = 0;i < m;i++) { if (imap[qi[i]][zhong[i]] == 0) sum++; imap[qi[i]][zhong[i]] = 1; imap[zhong[i]][qi[i]] = 1; } double ans = (double)sum / n; printf ("%.3lf\n",ans); } return 0;}
- 2014ACM集训13级PK赛3-Density of Power Network
- 2014ACM集训13级PK赛3-Yet Another Story of Rock-paper-scissors
- Density of Power Network
- Density of Power Network
- Density of Power Network
- 2014ACM集训13级PK赛3-Taxi Fare
- 2014ACM集训13级PK赛3-Modular Inverse
- 2014ACM集训13级PK赛3-Friends
- 2014ACM集训13级PK赛3-Java Beans
- ZOJ3708:Density of Power Network
- 2014寒假ACM集训13级PK赛-翻转排序
- 2014寒假ACM集训13级PK赛-购买矿石
- 2014ACM集训13级PK赛2-Somali Pirates
- 2014ACM集训13级PK赛2-Wu Xing
- 2014ACM集训13级PK赛2-Ordinal Numbers
- 2014ACM集训13级PK赛2-Conic Section
- 2014ACM集训13级PK赛2-Kagome Kagome
- 2014ACM集训13级PK赛2-Javabeans
- [内存管理]管理图解v0.1 v0.2 v0.3
- 链表逆序
- CoreData 概览
- 丁又专老师之作
- 学会定期备份
- 2014ACM集训13级PK赛3-Density of Power Network
- JavaMelody开源系统性能监控
- Android游戏开发
- 【Android自动化打包】01. aapt的用法
- awk命令详解
- VPS还是虚拟主机,究竟应该如何选择
- float和double类型数据做比较问题
- IBOutlet,IBAction简单的解释
- EJB 配置jboss 数据源 及 对数据库映射的实体Bean