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 ≤ NM ≤ 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->2   2->1视为同一条线段

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<stdlib.h>
     4 #include<algorithm>
     5 using namespace std;
     6 const int MAXN=1000;
     7 int s[MAXN][MAXN],star[MAXN],en[MAXN];
     8 int main()
     9 {
    10     //freopen("in.txt","r",stdin);
    11     int kase,n,m;
    12     scanf("%d",&kase);
    13     while(kase--)
    14     {
    15         memset(s,0,sizeof(s));
    16         scanf("%d %d",&n,&m);
    17         for(int i=0;i<m;i++)
    18             scanf("%d",&star[i]);
    19         for(int i=0;i<m;i++)
    20             scanf("%d",&en[i]);
    21         double cnt=0;
    22         for(int i=0;i<m;i++)
    23         {
    24             if(!s[star[i]][en[i]])
    25                 cnt++;
    26             s[star[i]][en[i]]=s[en[i]][star[i]]=1;
    27         }
    28         printf("%.3lf
    ",(double)cnt/n);
    29     }
    30     return 0;
    31 }
    View Code
  • 相关阅读:
    python机器学习:推荐系统实现(以矩阵分解来协同过滤)
    使用SAS,Stata,HLM,R,SPSS和Mplus的分层线性模型HLM
    R语言中小样本违反异方差性的线性回归
    R语言基于协方差的结构方程拟合的卡方检验
    R语言异方差回归模型建模:用误差方差解释异方差
    R语言中的生存分析Survival analysis晚期肺癌患者4例
    python列表的方法(改变原列表)
    python修改列表
    python列表的 + 、* 、in 、 not in 、 len() 、 max() 、 min()
    python切片(获取一个子列表(数组))
  • 原文地址:https://www.cnblogs.com/clliff/p/3920145.html
Copyright © 2011-2022 走看看