zoukankan      html  css  js  c++  java
  • ZOJ 3708 Density of Power Network

    Density of Power Network

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    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
    

    Author: WANG, Yelei
    Contest: The 10th Zhejiang Provincial Collegiate Programming Contest

     1 #include <cstdio>
     2 #include <cstring>
     3 using namespace std;
     4 
     5 const int maxn = 505;
     6 int nw[maxn][maxn];
     7 int sb[maxn], eb[maxn];
     8 int main()
     9 {
    10     int ca,n,m,num;
    11     scanf("%d", &ca);
    12     while (ca--)
    13     {
    14         num = 0;
    15         memset(nw, 0, sizeof(nw));
    16         scanf("%d%d", &n, &m);
    17         for (int i = 0; i < m; i++)
    18             scanf("%d", &sb[i]);
    19         for (int i = 0; i < m; i++)
    20             scanf("%d", &eb[i]);
    21         for (int i = 0; i < m; i++)
    22         {
    23             if (!nw[sb[i]][eb[i]])
    24             {
    25                 num++; nw[sb[i]][eb[i]]=nw[eb[i]][sb[i]]= 1;
    26             }
    27         }
    28         printf("%.3lf
    ", (double)num / (double)n);
    29     }
    30 }
  • 相关阅读:
    类中静态方法
    子类执行父类的构造方法
    MySQL grant命令使用
    Jmeter中引入class文件的方法
    了解CSS/CSS3原生变量var (转)
    Vue 开源项目库汇总(转)
    史上最全常用正则表达式 (转)
    如何实现CSS限制字数,超出部份显示点点点...
    我的博客园第一篇文章......
    平衡二叉树,AVL树之图解篇
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5465844.html
Copyright © 2011-2022 走看看