博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu4081 次小生成树变形
阅读量:6318 次
发布时间:2019-06-22

本文共 3426 字,大约阅读时间需要 11 分钟。

Problem Description
During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally conquered all six other kingdoms and became the first emperor of a unified China in 221 BC. That was Qin dynasty ---- the first imperial dynasty of China(not to be confused with the Qing Dynasty, the last dynasty of China). So Ying Zheng named himself "Qin Shi Huang" because "Shi Huang" means "the first emperor" in Chinese.
Qin Shi Huang undertook gigantic projects, including the first version of the Great Wall of China, the now famous city-sized mausoleum guarded by a life-sized Terracotta Army, and a massive national road system. There is a story about the road system:
There were n cities in China and Qin Shi Huang wanted them all be connected by n-1 roads, in order that he could go to every city from the capital city Xianyang.
Although Qin Shi Huang was a tyrant, he wanted the total length of all roads to be minimum,so that the road system may not cost too many people's life. A daoshi (some kind of monk) named Xu Fu told Qin Shi Huang that he could build a road by magic and that magic road would cost no money and no labor. But Xu Fu could only build ONE magic road for Qin Shi Huang. So Qin Shi Huang had to decide where to build the magic road. Qin Shi Huang wanted the total length of all none magic roads to be as small as possible, but Xu Fu wanted the magic road to benefit as many people as possible ---- So Qin Shi Huang decided that the value of A/B (the ratio of A to B) must be the maximum, which A is the total population of the two cites connected by the magic road, and B is the total length of none magic roads.
Would you help Qin Shi Huang?
A city can be considered as a point, and a road can be considered as a line segment connecting two points.
 

Input
The first line contains an integer t meaning that there are t test cases(t <= 10).
For each test case:
The first line is an integer n meaning that there are n cities(2 < n <= 1000).
Then n lines follow. Each line contains three integers X, Y and P ( 0 <= X, Y <= 1000, 0 < P < 100000). (X, Y) is the coordinate of a city and P is the population of that city.
It is guaranteed that each city has a distinct location.
 

Output
For each test case, print a line indicating the above mentioned maximum ratio A/B. The result should be rounded to 2 digits after decimal point.
 

Sample Input
 
2 4 1 1 20 1 2 30 200 2 80 200 1 100 3 1 1 20 1 2 30 2 2 40
 

Sample Output
 
65.00 70.00
 
/**hdu4081 次小生成树变形题目大意:给定n个城市,每一个城市有ai个人,在这些城市间修路,已知能够免费修一条路。其它路费用为长度,求免费路连接城市人口和修路总费用比值的最大值解题思路:我们要枚举每条路作为免费路的情况。能够先求出最小生成树sum。假设枚举的边在生成树上就(ai+a[j])/(sum-该边)。假设边不在生成树上          (ai+aj)/(sum-mlen[i][j]) mlen是加上当前边到最小生成树后必定组成的环上除当前边外最大权值边的权值。事实上就是一个次小生成树求解*/#include 
#include
#include
#include
#include
using namespace std;const int maxn=1010;const double inf=1e14;struct note{ int x,y,z;}p[maxn];double a[maxn][maxn],dis[maxn];int pre[maxn],n;int flag[maxn][maxn],vis[maxn];double mlen[maxn][maxn];double prim(int u){ double sum=0; memset(flag,0,sizeof(flag)); memset(vis,0,sizeof(vis)); memset(mlen,0,sizeof(mlen)); for(int i=1; i<=n; i++) { dis[i]=a[u][i]; pre[i]=u; } vis[u]=1; for(int i=1; i

转载地址:http://drkaa.baihongyu.com/

你可能感兴趣的文章
图片等文件信息上传阿里云
查看>>
RAID深入讲解--文件系统inode和格式介绍(2、3)
查看>>
Linux 运维实践案例-2015年12月20日-12月31日
查看>>
第二章 大网 三层交换机
查看>>
MongoDB Shell简单操作
查看>>
13Exchange Server 2010跨站点部署-证书配置
查看>>
datetime.timedelta计算2个时间的时间差
查看>>
bash的变量中存放的字符串的处理方式
查看>>
1、redis基本概念简介
查看>>
音频噪声抑制(1):经典滤波器篇
查看>>
【24】Python装饰器笔记
查看>>
packetix ***连不上问题解决方法
查看>>
JavaScript获取文本框光标的像素位置3
查看>>
Oracle笔记(二) SQLPlus命令
查看>>
hp unix 参数
查看>>
以太坊
查看>>
RHEL5/centos5上安装配置iscsi server
查看>>
Express 400 Error: ENOENT, open
查看>>
RedHat 6 配置iSCSI服务
查看>>
Django安装和基本用法
查看>>