prim + 邻接矩阵储存两点间最大距离,然后枚举即可。

#include<iostream>
#include<string>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<list>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<fstream>using namespace std;
typedef long long ll;const int maxn = 1010,INF = 0x3f3f3f3f;int fa[maxn],n;
vector<int> son[maxn];
int x[maxn],y[maxn],pop[maxn];
double maxr[maxn][maxn];//最小生成树中两点间的最大边
double sum,ans;
double e[maxn][maxn];struct Edge{int to,from;double val;bool operator < (const Edge &x) const{return val < x.val;}
};int getfa(int x){if (fa[x] == x) return x;else return fa[x] = getfa(fa[x]);
}
inline double pf(double x){return x * x;
}
inline double getdis(int u,int v){return sqrt(pf(x[u] - x[v]) + pf(y[u] - y[v]));
}void buildEdge(){for(int i = 1;i <= n;++i)for(int j = i+1;j <= n;++j){double dis = getdis(i, j);e[i][j] = e[j][i] = dis;}
}void prim()
{bool vis[maxn] = {};double dist[maxn] = {};for(int i = 1;i <= n;++i) {dist[i] = INF;}vector<int> v;int now = 1;int pre[maxn] = {};sum = 0;vis[1] = true;dist[1] = 0;v.push_back(1);for(int i = 1;i < n;++i){for(int j = 1;j <= n;++j){if(!vis[j] && e[now][j] < dist[j]){pre[j] = now;dist[j] = e[now][j];}}double mi = INF;int k = i;for(int j = 1;j <= n;++j){if(!vis[j] && dist[j] < mi){mi = dist[j];k = j;}}sum += dist[k];now = k;vis[k] = 1;for(int j = 0;j < v.size();++j){maxr[v[j]][k] = maxr[k][v[j]] = max(maxr[v[j]][pre[k]],dist[k]);}v.push_back(k);}
}void solve(){double ans = 0;for(int i = 1;i <= n;++i)for(int j = i + 1;j <= n;++j){double A = pop[i] + pop[j];double B = sum - maxr[i][j];ans = max(ans,A/B);}printf("%.2f\n",ans);
}void init(){cin >> n;for(int i = 1;i <= n;++i){cin >> x[i] >> y[i] >> pop[i];}memset(maxr,0,sizeof maxr);for(int i = 1;i <= n;++i) {for(int j = i + 1;j <= n;++j)e[i][j] = e[j][i] = INF;}buildEdge();prim();solve();
}int main(){int t;cin >> t;while(t--){init();}
}

UVALive - 5713 Qin Shi Huang's National Road System相关推荐

  1. Qin Shi Huang's National Road System HDU - 4081

    Qin Shi Huang's National Road System (HDU - 4081) 次小生成树的思想 题目描述 During the Warring States Period of ...

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

    题目链接:点击打开链接 Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

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

    Qin Shi Huang's National Road System( 次小生成树 ) During the Warring States Period of ancient China(476 ...

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

  5. Qin Shi Huang's National Road System

    Qin Shi Huang's National Road System 题目大意: Problem Description During the Warring States Period of a ...

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

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

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

    题目描述: During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms ...

  9. HDU 4081 Qin Shi Huang's National Road System (次小生成树算法)

    转载自http://blog.csdn.net/shuangde800 D_Double 题目: Problem Description During the Warring States Perio ...

最新文章

  1. 刀片服务器在现有数据中心的应用策略
  2. Spark之 spark简介、生态圈详解
  3. KNN(K-Nearest Neighbor)分类算法原理
  4. 关于一个Panel上鼠标不及时响应MouseLeave事件
  5. 【dfs】虫食算(ybtoj dfs-1-3)
  6. html基础电子文档,html基础
  7. iframe缓存无法清空_详解Http缓存机制
  8. ONNX系列二 --- 使用ONNX使Keras模型可移植
  9. 还可以这样玩?揭秘打通线上线下新思路
  10. C++--第0课 - 学习C++的意义
  11. 【基础知识】【中缀转逆波兰(后缀)表达式】
  12. cs1.6的c语言源代码,cs1.6source - 源码下载|游戏|其他游戏|源代码 - 源码中国
  13. 无线网卡mac地址修改
  14. Eclipse基础--安装eclipse及语言包
  15. 【企业微信点餐系统】
  16. dsscocx控件出错怎么办_关于解决OCX控件调用失败问题的总结
  17. linux强制删除只读文件夹,强制删除文件夹linux的方法是什么
  18. 保镖机器人作文_暴力“保镖”作文800字
  19. 基于Processing的躲避球游戏
  20. matlab画莫尔圆代码,EXCEL莫尔圆.xls

热门文章

  1. 单元测试中不能加入参数
  2. MyBatis 遇到 Error updating database.问题
  3. 计算机数值方法之最小二乘法拟合多项式C语言
  4. 想成为优秀的程序员这些码德不能缺
  5. 打印设置自定义表尾_教大家Excel2013表格中如何打印固定的表头和表尾
  6. 各大手机厂商快应用入口
  7. NVIDIA GeForce RTX 3080 with CUDA capability sm_86 is not compatible with the current PyTorch
  8. HCIA网络课程第一周作业
  9. 一键下载网页所有图片,把美丽存下来
  10. 像 IDE 一样使用 vim