ZOJhttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1914

POJhttp://poj.org/problem?id=2349

UVAhttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1310

题目大意,给定一些点的坐标,求MST,然后要求求去掉最大的k条边后,最大的边

直接Prim,然后在排序即可。

小技巧是一开始不求平方根,最后输出的时候在求出平方根即可。

ZOJ上排行第三,不过在POJ就被虐了。。。

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=501;
const int INF=9999999;
int map[MAXN][MAXN];
double dis[MAXN];
struct point
{
int x,y;
}ship[MAXN]; void prim(int n)
{
int i,j;
for(i=1;i<=n;i++)
dis[i]=INF; bool vis[MAXN]={0}; int cur=1;
vis[cur]=1;
dis[cur]=0; for(i=1;i<=n;i++)
{
double mini=INF;
for(j=1;j<=n;j++)
if(!vis[j] && dis[j] > map[cur][j])
dis[j]=map[cur][j]; for(j=1;j<=n;j++)
if(!vis[j] && mini > dis[j])
mini=dis[cur=j]; vis[cur]=true;
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,x;
scanf("%d%d",&x,&n); int i,j;
for(i=1;i<=n;i++)
scanf("%d%d",&ship[i].x,&ship[i].y); for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
map[i][j]= map[j][i] =
(ship[j].y -ship[i].y) *(ship[j].y -ship[i].y) + (ship[j].x -ship[i].x)*(ship[j].x -ship[i].x);
}
} prim(n); sort(dis+1,dis+n+1);
printf("%.2lf\n",sqrt(dis[n-x+1]));
}
return 0;
}

ZOJ 1914 Arctic Network (POJ 2349 UVA 10369) MST的更多相关文章

  1. ZOJ 1914 Arctic Network (POJ 2349) MST

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1914 http://poj.org/problem?id=2349 题目大 ...

  2. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

  3. ZOJ - 1586 QS Network (Prim)

    ZOJ - 1586 QS Network (Prim) #include<iostream> #include<cstring> using namespace std; + ...

  4. Java实现偶数矩阵(Even Parity, UVa 11464)

    偶数矩阵(Even Parity, UVa 11464) 问题描述 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1, 使得每个元素的上.下.左.右的元素(如果存在的话)之和 ...

  5. POJ 2349 Arctic Network (最小生成树)

    Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...

  6. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  7. [Poj2349]Arctic Network(二分,最小生成树)

    [Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...

  8. poj 1144 Network(无向图求割顶数)

    题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...

  9. POJ 1966 Cable TV Network(顶点连通度的求解)

                               Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissi ...

随机推荐

  1. Android 将HTML5封装成android应用APK文件的几种方法

    越来越多的开发者热衷于使用html5+JavaScript开发移动Web App.不过,HTML5 Web APP的出现能否在未来取代移动应用,就目前来说,还是个未知数.一方面,用户在使用习惯上,不喜 ...

  2. System.GC.Collect();//垃圾回收,回收没有正常关闭的http连接

    System.GC.Collect();//垃圾回收,回收没有正常关闭的http连接

  3. 12、UVC&V4L2的关系

    UVC是一种usb视频设备驱动.用来支持usb视频设备,凡是usb接口的摄像头都能够支持 V4L2是Linux下的视频采集框架.用来统一接口,向应用层提供API UVC: USB video clas ...

  4. iOS开发--漫谈内存管理(一)

    1.MRC与ARC 苹果提供两种内存管理机制:一种是MRC(manual reference count),即手动引用计数:还有一种是ARC(auto reference count).即自己主动引用 ...

  5. cocoapod卡在了analyzing dependencies

    尽管公司的项目没有使用cocoapod,可是有一些第三方库本身依赖其它第三方的库,而且是用cocoapod来管理这些依赖的.所以在使用某些第三方库时.还是须要用到cocoapod的.今天在github ...

  6. Hirens Boot DVD 15.2 功能恢复版 v1.1 -- 制作U盘启动盘

    Hirens Boot DVD 15.2 功能恢复版 v1.1 这个版本比 Hirens Boot DVD 15.2 功能要多,在正式版本中缺少的商业工具这个版本都包含了,所以这个应用程序被称为恢复版 ...

  7. Exploring Micro-frameworks: Spring Boot--转载

    原文地址:http://www.infoq.com/articles/microframeworks1-spring-boot Spring Boot is a brand new framework ...

  8. Pairs Forming LCM

    题目: B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB Description Find the result of ...

  9. POJ 1654 Area 凸包面积

    水题直接码... /********************* Template ************************/ #include <set> #include < ...

  10. php函数,static,globalkeyword及三种变量作用域

    函数 和js函数相似,关注php与其它语言不用的地方 函数的形參默认值 形式: function f($a,$b=3,$vc = "abc"){ } 注意:没有给默认值的形參必须传 ...