hdu 3405 world islands
求删点后最小的生成树,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;
}
hdu 3405 world islands的更多相关文章
- Poj 3771 hdu 3405
poj 3771 http://poj.org/problem?id=3771 wiki Prim http://zh.wikipedia.org/wiki/%E6%99%AE%E6%9E%97%E5 ...
- hdu 3405 删掉某点后 求最小生成树
给出N个点的坐标 边的权值为两点间的距离 删掉其中某点 求最小生成树的权值和 要求这权值最小 因为最多50个点 所以具体是删哪个点 用枚举假如有4个点 就要求4次最小生成树 分别是2 3 4 | 1 ...
- HDU 1668 Islands and Bridges
Islands and Bridges Time Limit: 4000ms Memory Limit: 65536KB This problem will be judged on HDU. Ori ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 4738 Caocao's Bridges(Tarjan求桥+重边判断)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 2112 (最短路+map)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 HDU Today Time Limit: 15000/5000 MS (Java/Others) ...
- HDU 4280 Island Transport(网络流)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...
- HDU 4280 Island Transport(网络流,最大流)
HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
随机推荐
- poll调用深入解析
poll调用深入解析http://blog.csdn.net/zmxiangde_88/article/details/8099049 poll调用和select调用实现的功能一样,都是网络IO利用的 ...
- JDK 安装环境配置(ubuntu)
在Ubuntu 上安装jdk,先去官网下载相对应的tar包 网址:(这是jdk1.8) http://www.oracle.com/technetwork/java/javase/downloads/ ...
- 图解单片机8位PWM、16位PWM中“位”的含义!
今天 发现很多同学 搞不懂单片机的pwm中的位表示什么意思,如很多同学会问“8位pwm.16位pwm是什么意思啊,它们有什么区别啊,其中的‘位’表示什么意思啊”.对于这些问题,今天就给大家解释下,由于 ...
- SharePoint2010 部署步骤“激活功能”中出现错误:无法启动计算机“PCName”上的服务SPUserCodeV4
在SharePoint2010开发中,选择部署类型为“部署为沙盒解决方案”,在部署代码是出现如下错误提示: 部署步骤“激活功能”中出现错误:无法启动计算机“PCName”上的服务SPUserCodeV ...
- Tesseract Ocr引擎
Tesseract Ocr引擎 1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/t ...
- 24篇HTTP博客
http://www.cppblog.com/woaidongmao/category/11721.html
- 从svn下载项目后build path为灰色
今天从svn上下载项目后,想加入下面jar包.可是build path为灰色. 解决的方法是:1.在项目上右键properties---project facts 如图所看到的: 点击右側conver ...
- Google App Engine 学习和实践
这个周末玩了玩Google App Engine,随手写点东西,算是学习笔记吧.不当之处,请多多指正. 作者:liigo,2009/04/26夜,大连 原创链接:http://blog.csdn.ne ...
- Leetcode:find_minimum_in_rotated_sorted_array
一. 题目 给定一个排好序的数组.数组可能是单调递增,也可能有一个变换. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2) 要求找出最小的数. ...
- 解决ORA-28000: the account is locked
原文地址:http://yanwushu.sinaapp.com/ora-28000-the-account-is-locked/ 在oracle中.连续十次尝试登陆不成功.那么此账户将会被锁定(lo ...