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 ...
随机推荐
- Collections.sort方法对list排序的两种方式
Collections.sort( )分为两部分,一部分为排序规则,一部分为排序算法 . 规则用来判断对象,算法则考虑如何进行排序 对于自定义对象,sort()不知道规则,所以无法比较,这种情况下一定 ...
- ARMv8 Linux内核源代码分析:__flush_dcache_all()
1.1 /* * __flush_dcache_all() * Flush the wholeD-cache. * Corrupted registers: x0-x7, x9-x11 */ EN ...
- PHP - MySQL数据库
第15章 MySQL数据库 学习要点: 1.Web数据库概述 2.MySQL的操作 3.MySQL常用函数 4.SQL语句详解 5.phpMyadmin 一.Web数据库概述 现在,我们已经熟悉了PH ...
- CentOS桌面环境如何打开终端以及如何将终端加入右键
安装完CentOS的桌面环境后,默认在桌面以及右键是没有打开终端选项的,要想打开终端,可以由以下步骤: 在左上角菜单[Applications]--->[System Tools]---> ...
- Objective-C中的SEL、IMP和Class类型
1.SEL类型 例子: SEL say; SEL skin; Objective-C 在编译的时候, 会根据方法的名字(包括参数序列),生成一个用 来区分这个方法的唯一的一个 ID,这个 ...
- hdu4712 Hamming Distance
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...
- HDU 1425 sort 题解
选择出数列中前k个最大的数. 这里由于数据特殊.所以能够使用hash表的方法: #include <cstdio> #include <algorithm> #include ...
- N使用exus2打造企业maven仓库(三)
假设项目中,我没有使用maven,我应该做出选择,或为项目.或者用它来推动这个项目从maven.有人会问,为什么maven?无需maven我们没有很好的操作. 这里,只说两件事情我最欣赏:第一点是管理 ...
- SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...
- MSSQL - 通用存储过程
通用插入存储过程: -- ============================================= -- Author: HF_Ultrastrong -- Create date: ...