zoukankan      html  css  js  c++  java
  • 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
    ",(double)sum/n);
        }
        return 0;
    }
    


     

  • 相关阅读:
    Fiddler显示响应时间
    WPF RichTextBox
    设计模式摘要
    sqlite insert时一直报constraint 约束
    try catch使用规则
    关于WPF的2000件事 06--WPF布局
    SmartAssembly 汉化说明
    GP80系列打印机驱动 V17下载地址
    记录 java 安卓 各类引用包报错处理方法 例如 android.support.v4.app.+ ,io.reactivex.+
    第一讲 新手如何学习HTTP协议之实践项目多开微信机器人
  • 原文地址:https://www.cnblogs.com/riskyer/p/3221531.html
Copyright © 2011-2022 走看看