题意:

秦始皇要建路,一共有n个城市,建n-1条路连接。

给了n个城市的坐标和每个城市的人数。

然后建n-2条正常路和n-1条魔法路,最后求A/B的最大值。

A代表所建的魔法路的连接的城市的市民的人数的和,B 代表n-2条正常路的长度的和。

思路:

这题是次小生成树的变形,所谓次小生成树的核心应该是记录树上节点间的路中最大的边的权重,然后将这条边替换为非最小生成树中的边,然后枚举找到最小值。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define INF 0x3f3f3f3f
using namespace std;
struct city{
int x,y,p;
};
city jilu[];
int n,from[];
double dp[][],dis[],total;
bool vis[];
double cal(city a,city b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void prim(int pos){
vis[pos]=;
for(int i=;i<n;i++){
if(dis[i]>cal(jilu[pos],jilu[i])){
dis[i]=cal(jilu[pos],jilu[i]);
from[i]=pos;
}
}
int next=-;
double mmin=1e32;
for(int i=;i<n;i++){
if(vis[i]==&&mmin>dis[i]){
mmin=dis[i];
next=i;
}
}
if(next>){
for(int i=;i<n;i++){
if(vis[i]){
dp[i][next]=max(dp[i][from[next]],mmin);
}
}
total+=mmin;
prim(next);
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d%d",&jilu[i].x,&jilu[i].y,&jilu[i].p);
}
for(int i=;i<n;i++){
dis[i]=1e32;
}
memset(dp,,sizeof(dp));
memset(vis,,sizeof(vis));
total=;
prim();
double ans=-;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(i!=j){
ans=max(ans,(jilu[i].p+jilu[j].p)*1.0/(total-max(dp[i][j],dp[j][i])));
}
}
}
printf("%.2lf\n",ans);
}
}

HDU 4081 Qin Shi Huang's National Road System [次小生成树]的更多相关文章

  1. HDU 4081 Qin Shi Huang's National Road System 次小生成树变种

    Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  2. hdu 4081 Qin Shi Huang's National Road System (次小生成树的变形)

    题目:Qin Shi Huang's National Road System Qin Shi Huang's National Road System Time Limit: 2000/1000 M ...

  3. HDU 4081 Qin Shi Huang's National Road System 最小生成树+倍增求LCA

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4081 Qin Shi Huang's National Road System Time Limit: ...

  4. hdu 4081 Qin Shi Huang's National Road System (次小生成树)

    Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  5. HDU 4081—— Qin Shi Huang's National Road System——————【次小生成树、prim】

    Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  6. HDU4081 Qin Shi Huang's National Road System —— 次小生成树变形

    题目链接:https://vjudge.net/problem/HDU-4081 Qin Shi Huang's National Road System Time Limit: 2000/1000 ...

  7. hdu 4081 Qin Shi Huang's National Road System 树的基本性质 or 次小生成树思想 难度:1

    During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in Ch ...

  8. hdu 4081 Qin Shi Huang's National Road System(次小生成树prim)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4081 题意:有n个城市,秦始皇要修用n-1条路把它们连起来,要求从任一点出发,都可以到达其它的任意点. ...

  9. HDU - 4081 Qin Shi Huang's National Road System 【次小生成树】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4081 题意 给出n个城市的坐标 以及 每个城市里面有多少人 秦始皇想造路 让每个城市都连通 (直接或者 ...

随机推荐

  1. python数据类型之int用法

    1.查看整型的用法 CODE:print(dir(int))['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', ...

  2. Javax.mail.NoSuchProviderException: smtp

    UT 这个错误是因为缺jar包 下载地址:在oralce下载一个 JavaMail 包 http://www.oracle.com/technetwork/java/javamail/index-13 ...

  3. [你必须知道的.NET]第一回:恩怨情仇:is和as

    本文将介绍以下内 容: • 类型转换 • is/as操作符小议 1. 引言 类型安全是.NET设计之初重点考虑 的内容之一,对于程序设计者来说,完全把握系统数据的类型安全,经常是力不从心的问题.现在, ...

  4. apache启用gzip压缩方法--转载自http://www.cnblogs.com/linzhenjie/archive/2013/03/05/2943635.html

    一.gzip介绍 Gzip是一种流行的文件压缩算法,现在的应用十分广泛,尤其是在Linux平台.当应用Gzip压缩到一个纯文本文件时,效果是非常明显的,大约可以减少70%以上的文件大小.这取决于文件中 ...

  5. Protocol Buffer基本介绍

    转自:http://www.cnblogs.com/stephen-liu74/archive/2013/01/02/2841485.html 该系列Blog的内容主体主要源自于Protocol Bu ...

  6. 每日学习心得:SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析)

    2013-8-20 1.    SQL查询表的行列转换/小计/统计(with  rollup,with cube,pivot解析) 在实际的项目开发中有很多项目都会有报表模块,今天就通过一个小的SQL ...

  7. MySQL数据库表中有usage字段名后的后果

    一个很奇怪的42000的错误,折腾了我一晚上.... 我的系统是Spring + SpringMVC + MyBatis结构, 数据库的mapper以及model等文件都是用MyBatisGenera ...

  8. Angular学习(2)- ng-app

    此例子看alert弹出时的效果.当然,最重要的是ng-app="MyApp",这一个是怎么加载的. <!DOCTYPE html> <html ng-app=&q ...

  9. 创建UIImage的两种方法

    1. UIImage *img = [UIImage imageNamed:@"imageName"]; 2. NSString *imageFilePath = [[NSBund ...

  10. Env:Cscope安装与配置

    1. 介绍 Cscope是类似于ctags一样的工具,但可认为他是ctags的增强版. 2. 安装 sudo apt-get install cscope 通过源码安装,参照http://blog.c ...