Zoj - 3708 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

题意:
要求您执行一个程序来计算电力系统的网络密度。网络密度定义为传输线数与母线数之比。请注意,如果连接同一对总线的两条或多条传输线,在拓扑分析中只计算一条。
两点之间的线再多只算一条。

#include<bits/stdc++.h>
const double PI=acos(-1.0);
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define inf 0x3f3f3f3f
#define pr pair<int,int>
typedef pair<char,int> PAIR;
struct CmpByValue
{
    bool operator()(const PAIR& lhs, const PAIR& rhs)
    {
        return lhs.second > rhs.second;
    }
};
//priority_qe<int,vector<int>,greater<int>> pp;
const int mod = 123456789 ;
const int M = 500 +10 ;
const int limt = 1<<20;
const int INF = 1e9;
typedef long long ll;
int mp[M][M];
int qq[M];
int pp[M];
int t,m,n;

/*
        题意:
        题意:每个样例第一行是公交车的数目与路线的数目,
        第二行是公交车起点,第三行是终点,
        从a->b与b->a是同一条路线,
        计算总路线与车辆数目的比值

*/
int main()
{
    //  ios::sync_with_stdio(0);
    scanf("%d",&t);
    while(t--)
    {
        //    cin>>n>>m;
        scanf("%d%d",&n,&m);
        memset(mp,0,sizeof(mp));
        for(int i=1; i<=m; i++)
            scanf("%d",&qq[i]);

        for(int i=1; i<=m; i++)
            scanf("%d",&pp[i]);

        int sum=0;
        double ans;

        for(int i=1; i<=m; i++)
        {
            if(mp[qq[i]][pp[i]]==0)//有不同的
                sum++;
            mp[pp[i]][qq[i]]=mp[qq[i]][pp[i]]=1;//已找到的
        }

        ans=(double)sum/n;
        printf("%.3f\n",ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值