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

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

题目大意,给定一些点的坐标,求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) MST的更多相关文章

  1. ZOJ 1914 Arctic Network (POJ 2349 UVA 10369) MST

    ZOJhttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1914 POJhttp://poj.org/problem?id=23 ...

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

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

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

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

  4. Arctic Network(洛谷)--北极通讯网络(loj)

    洛谷传送门 loj传送门 一道蛮基础的最小生成树的题 题意也没绕什么圈子 只是叙述的有点累赘而已(loj上是这样的 也就读入加建边需要稍稍稍多想一下下 对于我这么一个蒟蒻 这是一道很好的板子题 (洛谷 ...

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

    题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...

  6. ZOJ 1586 QS Network(Kruskal算法求解MST)

    题目: In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunica ...

  7. Network(poj 3694)

    题意:一个无向图可以有重边,下面q个操作,每次在两个点间连接一条有向边,每次连接后整个无向图还剩下多少桥(注意是要考虑之前连了的边,每次回答是在上一次的基础之上) /* tarjan+LCA 先用ta ...

  8. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

  9. ZOJ - 1586 QS Network (Prim)

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

随机推荐

  1. [转载]在C#中使用官方驱动操作MongoDB

    在C#中使用官方驱动操作MongoDB 8.1)下载安装 想要在C#中使用MongoDB,首先得要有个MongoDB支持的C#版的驱动.C#版的驱动有很多种,如官方提供的,samus. 实现思路大都类 ...

  2. A Neural Network in 11 lines of Python

    A Neural Network in 11 lines of Python A bare bones neural network implementation to describe the in ...

  3. 数据库里面DataTime时间类型字段,如果为null时

    tran.TransactionTime = bet.CreationDate.ToString() == "0001/1/1 0:00:00" ? DateTime.Now : ...

  4. show processlist 执行状态分析

    Sleep状态 通常代表资源未释放,如果是通过连接池,sleep状态应该恒定在一定数量范围内 实战范例:因前端数据输出时(特别是输出到用户终端)未及时关闭数据库连接,导致因网络连接速度产生大量slee ...

  5. linux zip 命令详解

    功能说明:压缩文件. 语 法:zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][-b <工作目录>][-ll][-n <字尾字符串>][-t <日期时 ...

  6. NSMutableArray,NSMutableDictionary的内存管问题

    今天做项目遇到一个问题,在一个类中定义了一个可变数组,使用的是copy的内存管理策略 当往数组中添加包装好的基本数据的时候,程序直接崩溃了.解决方法:把copy换成strong就不会崩溃了; 后来做了 ...

  7. UVA 658 It's not a Bug, it's a Feature!

    这个题目巧妙之处在于用二进制的每个位1,0分别表示bug的有无,以及实施补丁对相应bug的要求以及实施后的对bug的影响. 软件bug的状态:1表示相应bug仍然存在,0表示已经修复.这样可以将软件的 ...

  8. 5. Unity脚本的执行顺序

    Unity是不支持多线程的,也就是说我们必须要在主线程中操作它,可是Unity可以同时创建很多脚本,并且可以分别绑定在不同的游戏对象身上,他们各自都在执行自己的生命周期感觉像是多线程,并行执行脚本的, ...

  9. 自定义的IntentFileter 无法找到activity

    <intent-filter > <action android:name="com.leo.enjoytime.VIEW"/></intent-fi ...

  10. 【HDOJ】1540 Tunnel Warfare

    还不错的一道线段树区间合并.挺巧妙的用法. /* 1540 */ #include <iostream> #include <string> #include <map& ...