求删点后最小的生成树,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的更多相关文章

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

  2. hdu 3405 删掉某点后 求最小生成树

    给出N个点的坐标 边的权值为两点间的距离 删掉其中某点 求最小生成树的权值和 要求这权值最小 因为最多50个点 所以具体是删哪个点 用枚举假如有4个点 就要求4次最小生成树 分别是2 3 4 | 1 ...

  3. HDU 1668 Islands and Bridges

    Islands and Bridges Time Limit: 4000ms Memory Limit: 65536KB This problem will be judged on HDU. Ori ...

  4. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  5. HDU 4738 Caocao's Bridges(Tarjan求桥+重边判断)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu 2112 (最短路+map)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 HDU Today Time Limit: 15000/5000 MS (Java/Others)  ...

  7. HDU 4280 Island Transport(网络流)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...

  8. HDU 4280 Island Transport(网络流,最大流)

    HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...

  9. HDU 5643 King's Game 打表

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

随机推荐

  1. Hadoop源代码导入Eclipse

    须要进一步学习hadoop.须要看看内部源代码实现.因此须要将hadoop源代码导入都eclipse中,简单总结一下,详细过程例如以下: 首先确保已经安装了git.maven3.protobuf2.5 ...

  2. Action的返回值类型总结

    Action的返回值 MVC 中的 ActionResult是其他所有Action返回类型的基类,下面是我总结的返回类型,以相应的帮助方法: 下面是这些方法使用的更详细的例子 一.返回View     ...

  3. linux: 鸟哥的私房菜

    鸟哥的私房菜 http://vbird.dic.ksu.edu.tw/linux_basic/0320bash.php

  4. Microsoft Win32 Programmer's Reference.chm

    实在是太棒了,感谢这位网友: http://download.csdn.net/detail/tgyd6800/9632351

  5. 一则 ORA-00471 处理方法

    公司新上架一台服务到机房,硬件是IBM X3850 X5,硬件配置算是好的,内存有128GB.SA安装好系统--(版本sule 32bit)后通知我可以安装数据库了.忙活半天,安装好oracle 92 ...

  6. Coin Toss

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31329#problem/G 使用二维数组f[ i ] [ j  ] 表示前i 位中有j个 ...

  7. java中int,char,string三种类型的相互转换

    如何将字串 String 转换成整数 int? int i = Integer.valueOf(my_str).intValue(); int i=Integer.parseInt(str); 如何将 ...

  8. 使用POI来实现对Excel的读写操作

    事实上我感觉直接贴代码就好了.代码里面差点儿做到每一行一个凝视.应该看起来会比較简单 代码托管在github上:https://github.com/chsj1/ExcelUtils package ...

  9. 解 自己关于 C# Button的Click事件的疑惑

    先说说C#中事件的用法,从事件的用法中,我自己会产生一个疑惑 C#事件 class Program { static void Main(string[] args) { EventClass ec ...

  10. TCanvas.CopyRect方法中参数CopyMode的意义

    首先看可能取值: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 cmBlackness = BLACKNESS; cmDstInvert = DSTINVERT; cmMer ...