求删点后最小的生成树,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. 基于visual Studio2013解决C语言竞赛题之1048打印矩阵

      题目 解决代码及点评 /* 48. 找规律填写N×N方阵.如N=8时, 其方阵为: */ #include <stdio.h> #include <stdlib.h& ...

  2. EasyUI - ValidateBox 验证组件

    基本效果: 效果: Html代码: <input id="email" /> JS代码: 默认的有四种验证方式: email:验证邮箱 url:验证url length ...

  3. fzu 2035 Axial symmetry(枚举+几何)

    题目链接:fzu 2035 Axial symmetry 题目大意:给出n个点,表示n边形的n个顶点,判断该n边形是否为轴对称图形.(给出点按照图形的顺时针或逆时针给出. 解题思路:将相邻两个点的中点 ...

  4. [课堂实践与项目]NavigationController与TabBarController的综合使用及易错点分析(包含消息提醒,app更新)

    陈述:我们在使用tabbarController的时候,我们总会和NavagationController联合起来.但是不联合的时候又是什么样的一种pool的情况呢?我们就单单的 TabBarCont ...

  5. vc怎么去掉烦人的“驱动器未准备好”错误

    在我们写程序的时候,如果访问一个软驱中没有软盘或者光驱中没有cd的时候,windows总是弹出一个恼人的错误框说“驱动器未准备好” 其实我们可以通过如下的步骤禁止这个错误框的弹出 一.用SetErro ...

  6. Boost::thread库的使用

    阅读对象 本文假设读者有几下Skills [1]在C++中至少使用过一种多线程开发库,有Mutex和Lock的概念. [2]熟悉C++开发,在开发工具中,能够编译.设置boost::thread库. ...

  7. SQLiteLog (1) no such Column:

           今天在进入sqlite数据库查询的时候出现了这个问题,SQLiteLog (1) no such Column: BGZ 搜索得知这是因为数据库中没有这一列,我的sql语句为" ...

  8. Oracle 经常使用的改动语句

    一.表Table 測试表:MY_TEST_TABLE -- Create table create table MY_TEST_TABLE ( A VARCHAR2(30), B NUMBER(10) ...

  9. Unity 3D学习笔记(三)——关于脚本

    在脚本中定义的类成员,如果是公共的话,在脚本与游戏对象绑定之后,是可以在Inspector中编辑的,例如下面这个脚本: using UnityEngine; using System.Collecti ...

  10. Windows串口编程

    串口基础知识 http://www.cnblogs.com/menlsh/archive/2013/01/28/2880580.html DTU知识 http://blog.csdn.net/xuto ...