[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)(一)
841 0
|
关系型数据库 MySQL 数据库
mysql 提权
UDF提权是利用MySQL的自定义函数功能,将MySQL账号转化为系统system权限 下载lib_mysqludf_sys程序 github:https://github.
1442 0
|
物联网 API
设备端和服务端检测设备是否在线的方法
使用物联网时,有时设备端和服务端都需要检测设备是否在线。
2045 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
|
23天前
|
人工智能 自然语言处理 Shell
🦞 如何在 OpenClaw (Clawdbot/Moltbot) 配置阿里云百炼 API
本教程指导用户在开源AI助手Clawdbot中集成阿里云百炼API,涵盖安装Clawdbot、获取百炼API Key、配置环境变量与模型参数、验证调用等完整流程,支持Qwen3-max thinking (Qwen3-Max-2026-01-23)/Qwen - Plus等主流模型,助力本地化智能自动化。
33787 134
🦞 如何在 OpenClaw (Clawdbot/Moltbot) 配置阿里云百炼 API
|
6天前
|
人工智能 自然语言处理 监控
OpenClaw skills重构量化交易逻辑:部署+AI全自动炒股指南(2026终极版)
2026年,AI Agent领域最震撼的突破来自OpenClaw(原Clawdbot)——这个能自主规划、执行任务的智能体,用50美元启动资金创造了48小时滚雪球至2980美元的奇迹,收益率高达5860%。其核心逻辑堪称教科书级:每10分钟扫描Polymarket近千个预测市场,借助Claude API深度推理,交叉验证NOAA天气数据、体育伤病报告、加密货币链上情绪等多维度信息,捕捉8%以上的定价偏差,再通过凯利准则将单仓位严格控制在总资金6%以内,实现低风险高频套利。
2874 11
|
19天前
|
人工智能 安全 机器人
OpenClaw(原 Clawdbot)钉钉对接保姆级教程 手把手教你打造自己的 AI 助手
OpenClaw(原Clawdbot)是一款开源本地AI助手,支持钉钉、飞书等多平台接入。本教程手把手指导Linux下部署与钉钉机器人对接,涵盖环境配置、模型选择(如Qwen)、权限设置及调试,助你快速打造私有、安全、高权限的专属AI助理。(239字)
7302 21
OpenClaw(原 Clawdbot)钉钉对接保姆级教程 手把手教你打造自己的 AI 助手
|
18天前
|
人工智能 机器人 Linux
OpenClaw(Clawdbot、Moltbot)汉化版部署教程指南(零门槛)
OpenClaw作为2026年GitHub上增长最快的开源项目之一,一周内Stars从7800飙升至12万+,其核心优势在于打破传统聊天机器人的局限,能真正执行读写文件、运行脚本、浏览器自动化等实操任务。但原版全英文界面对中文用户存在上手门槛,汉化版通过覆盖命令行(CLI)与网页控制台(Dashboard)核心模块,解决了语言障碍,同时保持与官方版本的实时同步,确保新功能最快1小时内可用。本文将详细拆解汉化版OpenClaw的搭建流程,涵盖本地安装、Docker部署、服务器远程访问等场景,同时提供环境适配、问题排查与国内应用集成方案,助力中文用户高效搭建专属AI助手。
5142 12

热门文章

最新文章