[ACM_图论] ZOJ 3708 [Density of Power Network 线路密度,a->b=b->a去重]

简介:


 

 

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

 

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

解题思路:水题,不解释。

 

复制代码
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<string.h>
 4 #include<stdio.h>
 5 #include<set>
 6 using namespace std;
 7 int main(){
 8     int T;
 9     cin>>T;
10     while(T--){
11         int N,M;
12         cin>>N>>M;
13         int start[505],end[505];
14         for(int i=0;i<M;i++)
15             cin>>start[i];
16         for(int i=0;i<M;i++)
17             cin>>end[i];
18 
19         int curM=M;
20         for(int i=0;i<M-1;i++){
21             for(int j=i+1;j<M;j++){
22                 if((start[i]==start[j] && end[i]==end[j])
23                 ||(start[i]==end[j] && end[i]==start[j])){
24                     curM--;
25                     break;
26                 }
27             }
28         }
29 
30         printf("%.3lf\n",curM/(1.0*N));
31     }return 0;
32 
33 }
复制代码
相关文章
|
JSON 前端开发 JavaScript
前端AJAX入门到实战,学习前端框架前必会的(ajax+node.js+webpack+git)(一)
前端AJAX入门到实战,学习前端框架前必会的(ajax+node.js+webpack+git)(一)
776 0
|
物联网 API
设备端和服务端检测设备是否在线的方法
使用物联网时,有时设备端和服务端都需要检测设备是否在线。
1939 0
|
分布式计算 资源调度 Hadoop
Hadoop运行环境搭建(开发重点四)在hadoop102安装hadoop、配置hadoop环境变量、测试Hadoop是否安装成功、hadoop重要目录
Hadoop运行环境搭建(开发重点四)在hadoop102安装hadoop、配置hadoop环境变量、测试Hadoop是否安装成功、hadoop重要目录
Hadoop运行环境搭建(开发重点四)在hadoop102安装hadoop、配置hadoop环境变量、测试Hadoop是否安装成功、hadoop重要目录
|
机器学习/深度学习 人工智能 自然语言处理
程序人生——聊聊人工智能、元宇宙、NFT和WEB3.0
程序人生——聊聊人工智能、元宇宙、NFT和WEB3.0
程序人生——聊聊人工智能、元宇宙、NFT和WEB3.0
|
3天前
|
云安全 人工智能 自然语言处理
|
7天前
|
人工智能 Java API
Java 正式进入 Agentic AI 时代:Spring AI Alibaba 1.1 发布背后的技术演进
Spring AI Alibaba 1.1 正式发布,提供极简方式构建企业级AI智能体。基于ReactAgent核心,支持多智能体协作、上下文工程与生产级管控,助力开发者快速打造可靠、可扩展的智能应用。
708 17
|
10天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
746 57
Meta SAM3开源:让图像分割,听懂你的话
|
8天前
|
搜索推荐 编译器 Linux
一个可用于企业开发及通用跨平台的Makefile文件
一款适用于企业级开发的通用跨平台Makefile,支持C/C++混合编译、多目标输出(可执行文件、静态/动态库)、Release/Debug版本管理。配置简洁,仅需修改带`MF_CONFIGURE_`前缀的变量,支持脚本化配置与子Makefile管理,具备完善日志、错误提示和跨平台兼容性,附详细文档与示例,便于学习与集成。
329 116