求删点后最小的生成树,n<50.。。。数据好弱,直接暴力枚举就行。。。删点的时候直接g[i][j]=INF就行了。

#include<iostream>
#include<algorithm>
#include<fstream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(i=a; i<b; i++)
#define FD(i, a, b) for(i=a; i>b; i--)
#define CLR(a, b) memset(a, b, sizeof(a))
#define LL long long
#define CPY(a, b) memcpy(a, b, sizeof(b))
using namespace std;
ofstream fout ("output.txt");
ifstream fin ("input.txt");const int maxn = 100;
const double INF = 222222;
int T, n;
double g[maxn][maxn], low[maxn], x[maxn], y[maxn], tmp[maxn][maxn];
bool vis[maxn];double prim(int start)
{double  min, res=0;int i, j, pos;CLR(vis, 0);vis[start] = 1; pos = start;FF(i, 1, n+1)   if(i!=pos) low[i] = g[pos][i];FF(i, 1, n){min = INF;FF(j, 1, n+1)if(vis[j] == 0 && min > low[j])min = low[j], pos = j;res += min;vis[pos] = 1;FF(j, 1, n+1)if(vis[j] == 0 && low[j] > g[pos][j])low[j] = g[pos][j];}return res;
}int main()
{scanf("%d", &T);while(T--){int i, j;scanf("%d", &n);FF(i, 1, n+1)  scanf("%lf%lf", &x[i], &y[i]);FF(i, 1, n+1)FF(j, 1, n+1)g[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));double ans = INF*INF;FF(i, 1, n+1){CPY(tmp, g);FF(j, 1, n+1){g[i][j] = g[j][i] = INF;}ans = min(ans, prim(1));CPY(g, tmp);}printf("%.2lf\n", n < 3 ? 0 : ans-INF);}return 0;
}

转载于:https://www.cnblogs.com/dyllove98/p/3188640.html

hdu 3405 world islands相关推荐

  1. Islands HDU - 2808

    题目链接:Islands HDU - 2808 =================================================== Islands Time Limit: 1000 ...

  2. HDU 4738 Caocao‘s Bridges(桥、任何位运算一定都要加括号、因为有重边所以用前向星)

    HDU 4738 Caocao's Bridges(桥.任何位运算一定都要加括号.因为有重边所以用前向星) Caocao was defeated by Zhuge Liang and Zhou Yu ...

  3. 【HDU - 4006】The kth great number (优先队列,求第k大的数)

    题干: Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to wri ...

  4. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  5. HDU 4738 Caocao's Bridges 求桥 诸葛亮带着炸弹跑路了

    Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't g ...

  6. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  7. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

  8. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  9. hdu 1312 Red and Black 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 第二条深搜,题目并不难,但是做了我好久好久,由于一个细节,让我赌上了一个晚上的时间. 题目大意: ...

最新文章

  1. python链接mysql 判断是否成功_【初学python】使用python连接mysql数据查询结果并显示...
  2. Python学习的十个阶段,学完大成,对应一下看看你自己在哪个阶段
  3. docker 开机自启动
  4. 微型计算机除具有计算机的一般特点外,10秋学期《计算机应用基础》第1次在线作业答案免费6/15...
  5. matlab怎么写集合,matlab集合操作
  6. 20.校准相机——直接线性校准不均匀,直接线性校准变换,几何误差_3
  7. 2021年德国汽车产量预计同比锐减18%
  8. matlab刚度矩阵求逆,ANSYS求结构整体刚度矩阵逆矩阵APDL命令流
  9. pandas读取文件自动生成表头
  10. mysql交互式服务检测_MySQL innotop实时监测工具
  11. Visual Studio中更改项目名称
  12. C++面向对象程序设计:地铁自动售票系统
  13. 给Ubuntu安装驱动(nvidia)保姆级教程(方法一)
  14. python3.7安装完成pip无法使用
  15. Spring AOP官网学习
  16. 2014.10.9——Jim Foley教授讲座How real is real enough?
  17. Python字符串相关方法
  18. 点击tab栏如何让tab置顶
  19. 身份证号校验(极简版)
  20. Pandas方法实践-2012美国总统竞选赞助数据分析

热门文章

  1. eslint关闭===替换==;eslint关闭全等于校验;eslint关闭==校验
  2. 深入react技术栈(5):React生命周期
  3. [html] 你有使用过output标签吗?说说它的用途有哪些?
  4. [vue] 使用vue写一个tab切换
  5. [vue] axios是什么?怎样使用它?怎么解决跨域的问题?
  6. 工作80:块级元素的间隙问题
  7. 前端学习(2369):组件的创建使用和组件的生命周期
  8. “约见”面试官系列之常见面试题之第六十篇之事件绑定和普通事件(建议收藏)
  9. “约见”面试官系列之常见面试题之第五十三篇之网站的资源优化(建议收藏)
  10. 前端学习(1400):多人管理20代码优化