zoukankan      html  css  js  c++  java
  • zoj3708 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

    //读懂题意就能过

    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    int g[1001][1001];
    int main()
    {
       int t;
       scanf("%d",&t);
       int up[1001];
       int down[1001];
       while(t--)
       {
           int n,m;
           scanf("%d%d",&n,&m);
           memset(g,0,sizeof(g));
           int Count=0;
           for(int i=1;i<=m;i++)
            scanf("%d",&up[i]);
           for(int j=1;j<=m;j++)
            scanf("%d",&down[j]);
           for(int k=1;k<=m;k++)
           {
               if(g[up[k]][down[k]]==0)
               {
                    g[up[k]][down[k]]=g[down[k]][up[k]]=1;
               }
               else
                Count++;
           }
           printf("%0.3lf\n",(m-Count)*1.0/n);
       }
       return 0;
    }


  • 相关阅读:
    Java实现 LeetCode 432 全 O(1) 的数据结构
    Java实现 LeetCode 432 全 O(1) 的数据结构
    Makefile 自动生成依赖
    比较详细的利用虚拟机对SD卡FAT32+EXT4+Ext4分区图解教程
    STM32F0308开发环境的选择--CooCox CoIDE篇
    linux下包管理命令yum与apt-get以及开发环境配置
    裸机编程与OS环境编程的有关思考
    Eclipse C/C++环境配置
    Linux Eclipse代码提示功能设置(Java & C/C++)
    Linux下高效编写Shell——shell特殊字符汇总
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3089474.html
Copyright © 2011-2022 走看看