题目大意:秦始皇要在n个城市之间修筑一条道路使得任意两个城市均可连通。有个道士可以用法力帮忙修一条路。秦始皇希望其他的道路总长B最短且用法术连接的两个城市的人口之和A尽量大,因此下令寻找一个A / B的最大方案。(转自http://blog.csdn.net/murmured/article/details/18865721,侵删)

题解:考虑修哪一条路,此时A确定,断掉这条路后,形成两个连通块,不难发现两个连通块都应是MST才能让B最短。此时B为两个连通块的MST权值和
这个过程相当于选了一条路u->v后,在整张图的MST上,把MST上u->v路径上最大边删掉。

其实不用枚举边,枚举u和v即可

空间开小了,RE了无数发。。。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
template<class T>
inline void swap(T &a, T &b)
{
T tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const int INF = 0x3f3f3f3f;
const int MAXN = + ;
const int MAXM = + ; int x[MAXM], y[MAXM], node[MAXM], n, m, t, u[MAXM], v[MAXM], cnt[MAXM], fa[MAXM], vis[MAXN];
double ma[MAXN][MAXN], w[MAXM];
struct Edge
{
int u,v,nxt;
double w;
Edge(int _u, int _v, double _w, int _nxt){u = _u;v = _v;w = _w;nxt = _nxt;}
Edge(){}
}edge[MAXM << ];
int head[MAXN], cntt;
inline void insert(int a, int b, double c)
{
edge[++cntt] = Edge(a,b,c,head[a]);
head[a] = cntt;
}
int find(int x){return x == fa[x] ? x : fa[x] = find(fa[x]);}
int cmp(int x, int y){return w[x] < w[y];} int tiaoshi;
void dfs(int x, int pre)
{
vis[x] = ;
for(int pos = head[x];pos;pos = edge[pos].nxt)
{
int v = edge[pos].v;
if(v == pre) continue;
for(int i = ;i <= n;++ i)
if(i == v || !vis[i]) continue;
else ma[i][v] =ma[v][i] = max(ma[i][v], max(ma[v][i], max(ma[x][i], max(ma[i][x], edge[pos].w))));
dfs(v, x);
}
}
int main()
{
read(t);
for(;t;--t)
{
tiaoshi = ;
read(n);memset(ma, , sizeof(ma)), memset(vis, , sizeof(vis)), memset(head, , sizeof(head)), cntt = , m = ;
for(int i = ;i <= n;++ i) read(x[i]), read(y[i]), read(node[i]);
for(int i = ;i <= n;++ i)
for(int j = i + ;j <= n;++ j)
++ m, u[m] = i, v[m] = j, w[m] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])), cnt[m] = m, fa[m] = m;
std::sort(cnt + , cnt + + m, cmp);
int tmp = ;
double ans = ;
double ans2 = ;
for(int i = ;i <= m;++ i)
{
int f1 = find(u[cnt[i]]), f2 = find(v[cnt[i]]);
if(f1 == f2) continue;
fa[f1] = f2;
insert(u[cnt[i]], v[cnt[i]], w[cnt[i]]), insert(v[cnt[i]], u[cnt[i]], w[cnt[i]]);
ans += w[cnt[i]];
++ tmp;if(tmp == n - ) break;
}
dfs(, -);
for(int i = ;i <= n;++ i)
for(int j = i + ;j <= n;++j)
{
if(ans == ma[i][j]) continue;
ans2 = max(ans2, (double)(node[i] + node[j]) / (ans - ma[i][j]));
}
printf("%.2lf\n", ans2);
}
return ;
}

LA5713

LA5713 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. UValive 5713 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 ...

  3. 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 ...

  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. Qin Shi Huang's National Road System HDU - 4081(树形dp+最小生成树)

    Qin Shi Huang's National Road System HDU - 4081 感觉这道题和hdu4756很像... 求最小生成树里面删去一边E1 再加一边E2 求该边两顶点权值和除以 ...

  6. [hdu P4081] Qin Shi Huang’s National Road System

    [hdu P4081] Qin Shi Huang’s National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  7. HDU4081 Qin Shi Huang's National Road System 2017-05-10 23:16 41人阅读 评论(0) 收藏

    Qin Shi Huang's National Road System                                                                 ...

  8. HDU4081: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 ...

  9. 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 ...

随机推荐

  1. P1919 【模板】A*B Problem升级版 /// FFT模板

    题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...

  2. neo4j中cypher语句多个模糊查询

    总结一下经验: neo4j中,cypher语句的模糊查询,好像是个正则表达式结构. 对于一个属性的多个模糊查询,可以使用如下写法: 比如,查询N类型中,属性attr包含'a1'或者'a2'的所有节点. ...

  3. C 遍历目录及其子目录

    遍历某一目录,获取该目录下所有文件路径的数组 #include <iostream> #include <dirent.h> #include <vector> v ...

  4. It's a Mod, Mod, Mod, Mod World (类欧几里得模板题

    https://vjudge.net/contest/317000#problem/F #include <iostream> #include <cstdio> #inclu ...

  5. SpringBoot配置自定义日期参数转换器

    1.自定义参数转换器 自定义参数转换器必须实现Converter接口 /** * Created by IntelliJ IDEA. * * @Auther: ShaoHsiung * @Date: ...

  6. Jquery实现图片瀑布流思路-简单版

    目录 Jquery实现图片瀑布流思路-简单版 1.预备 2.开始 1.声明 2.主体 3.窗体大小改变事件 Jquery实现图片瀑布流思路-简单版 注意:本篇文章基于知道每张图片的实际尺寸的情况下 特 ...

  7. 关于获取webview(窗口间关系)的方法

    1.获取指定页面ID的webview plus.webview.getWebviewById('为页面设置的id值'): 该方法主要用于首页底部导航切换到子页面时不执行子页面的函数,因为在设置导航的时 ...

  8. 《DSP using MATLAB》Problem 8.15

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  9. appscan如何扫描移动应用APP

    1.前置条件:让手机和电脑处于同一WIFI下 1打开appscan,选择手动探索/外部设备. 2在弹出的对话框页面点击右上角“记录代理配置”. 3在弹出的页面选择记录代理页签,设置Appscan代理端 ...

  10. springboot拦截器的拦截配置和添加多个拦截器

    在spring2.0之前的版本大部分都采用extends WebMvcConfigurerAdapter,把拦截器配置成一个bean,具体的方法,我不细说,网上一大堆.而在spring2.0之后,这个 ...