Qin Shi Huang's National Road System

HDU - 4081

感觉这道题和hdu4756很像...

求最小生成树里面删去一边E1 再加一边E2 求该边两顶点权值和除以(最小生成树-E1)的最大值

其中(最小生成树-E1)必须是最小的

先跑一遍prim 跑完之后在最小生成树里面dp

dp[i][j] = i到j的路径中最大的那条边 最小生成树减去dp[i][j]肯定会最小

代码如下

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const double inf = 0x3f3f3f3f3f;
const int maxn = ;
struct Point {
double x, y;
int n;
} point[maxn];
struct Edge {
int to;
int next;
} edge[maxn<<];
int n, cnt, head[maxn], pre[maxn];
double dis[maxn][maxn], lowc[maxn], sum, dp[maxn][maxn];
bool vis[maxn];
inline void addedge(int u, int v) {
edge[cnt].to = v;
edge[cnt].next = head[u];
head[u] = cnt++;
}
inline double Distance(const Point& lhs, const Point& rhs) {
return sqrt((lhs.x - rhs.x) * (lhs.x - rhs.x) + (lhs.y - rhs.y) * (lhs.y - rhs.y));
}
void prim() {
sum = 0.0;
memset(vis, , sizeof(vis));
memset(pre, , sizeof(pre));
for (int i = ; i < n; i++) lowc[i] = dis[][i];
vis[] = true;
for (int i = ; i < n; i++) {
double minc = inf;
int p = -;
for (int j = ; j < n; j++) {
if (!vis[j] && minc > lowc[j]) {
minc = lowc[j];
p = j;
}
}
sum += minc;
vis[p] = true;
addedge(p, pre[p]);
addedge(pre[p], p);
for (int j = ; j < n; j++) {
if (!vis[j] && lowc[j] > dis[p][j]) {
lowc[j] = dis[p][j];
pre[j] = p;
}
}
}
}
void dfs(int u, int root) {
vis[u] = true;
for (int i = head[u]; ~i; i = edge[i].next) {
int v = edge[i].to;
if (!vis[v]) {
dp[root][v] = max(dp[root][u], dis[u][v]);
dfs(v, root);
}
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%lf%lf%d", &point[i].x, &point[i].y, &point[i].n);
}
for (int i = ; i < n; i++) {
for (int j = i + ; j < n; j++) {
dis[i][j] = dis[j][i] = Distance(point[i], point[j]);
}
}
memset(head, -, sizeof(head));
cnt = ;
prim();
for (int i = ; i < n; i++) {
memset(vis, ,sizeof(vis));
dfs(i, i);
}
double ans = ;
for (int i = ; i < n; i++) {
for (int j = i + ; j < n; j++) {
double temp = sum - dp[i][j];
temp = (point[i].n + point[j].n) / temp;
ans = max(ans, temp);
}
}
printf("%.2f\n", ans);
}
return ;
}

Qin Shi Huang's National Road System HDU - 4081(树形dp+最小生成树)的更多相关文章

  1. LA 5713 - Qin Shi Huang's National Road System(HDU 4081) MST

    LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

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

  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 (次小生成树的变形)

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

  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: 32768/3 ...

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

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

随机推荐

  1. 【20190228】JavaScript-获取子元素

    在写JavaScript的时候发现了一个获取子节点的坑,如以下的html结构 <div id="parent"> <div>1</div> &l ...

  2. 国人如此浮躁为哪般? --- 我看2018年度AI圈八大造假事件华人独占6件

    国人如此浮躁为哪般? ---  我看2018年度AI圈八大造假事件华人独占6件 人工智能在2018年发展很快,取得了很多成绩:很多新的产品,框架,软硬件系统,层出不穷:以七巨头为首的业界头部企业也取得 ...

  3. 转载: ssh连接上华为云Linux服务器,一会就自动断开

    原文链接:https://www.cnblogs.com/mspeer/p/9907734.html 客户端向服务端发送心跳 依赖 ssh 客户端定时发送心跳,putty.SecureCRT.XShe ...

  4. asp.net/wingtip/创建数据访问层

    一. 什么是数据访问层 在wingtip项目中,数据访问层是对以下三者的总称:1. product类等数据相关的实体类(class)2. 数据库(database),对实体类成员的存储3. 上述二者的 ...

  5. serversql数据库的查询操作

    sql数据库 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !importan ...

  6. 修改文件属性(attrib)

    atrrib 命令: // 描述: (Attribute) 显示,设置或删除分配给文件或目录的属性. 如果在没有参数的情况下使用,attrib将显示当前目录中所有文件的属性. // 语法: attri ...

  7. Python面试笔记一

    目录 一.MySQL(30题) 二.django(15题) 三.Python部分(46题) 四.RESTful API设计指南(7题) 五.补充 一.MySQL(30题) 1.mysql如何做分页 m ...

  8. WMware workstation中几种网络连接的说明 【转】

    博客来源:WMware workstation中几种网络连接的说明 VMware workstation中几种网络连接的说明 WMware workstation中网络连接包括,桥接模式.NAT模式. ...

  9. 5.机器学习——DBSCAN聚类算法

    1.优缺点 优点: (1)聚类速度快且能够有效处理噪声点和发现任意形状的空间聚类: (2)与K-MEANS比较起来,不需要输入要划分的聚类个数: (3)聚类簇的形状没有偏倚: (4)可以在需要时输入过 ...

  10. python import详解

    1.import作用 引入模块 2.import的特点 一个程序中,import的模块不会重复被引用,如: # test1.py import test2 print test2.attr # tes ...