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. reboot---重启Linux系统

    reboot命令用来重新启动正在运行的Linux操作系统. 语法 reboot(选项) 选项 -d:重新开机时不把数据写入记录文件/var/tmp/wtmp.本参数具有“-n”参数效果: -f:强制重 ...

  2. 清除celery 任务队列

    celery 有密码的时候 清除任务 redis-cli -h host -p port -a password -n 11 ltrim transcode 0 196 没有密码的时候 redis-c ...

  3. 洛谷——P2984 [USACO10FEB]给巧克力Chocolate Giving

    https://www.luogu.org/problem/show?pid=2984 题目描述 Farmer John is distributing chocolates at the barn ...

  4. python生成md5, shell生成md5

    echo -n 'aaa'|md5sum|cut -d ' ' -f1 python用hashlib md5=hashlib.md5(mid.upper()).hexdigest().upper()

  5. using the easy connect naming method 简单连接測试

    一直都不明确sqlnet.ora中的NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)是什么意思.今天看到一篇文档,就是登陆选用的方式.做一个測试: tnsname ...

  6. Scala具体解释---------类

    Scala中的类 摘要: 在本篇中.你将会学习怎样用Scala实现类. 假设你了解Java或C++中的类,你不会认为这有多难.而且你会非常享受Scala更加精简的表示法带来的便利.本篇的要点包含: 1 ...

  7. ListCtrl添加右键菜单(在对话框类中)

    在对话框类中如何添加NM_RCLICK消息: ListCtrl控件右键单击选择属性 在右侧属性栏中选择控件事件 在控件事件中找到NM_RCLICK并添加 完成,写代码

  8. [Vue + TS] Create Type-Safe Vue Directives in TypeScript

    Directives allow us to apply DOM manipulations as side effects. We’ll show you how you can create yo ...

  9. HDU 5389 Zero Escape (MUT#8 dp优化)

    [题目链接]:pid=5389">click here~~ [题目大意]: 题意: 给出n个人的id,有两个门,每一个门有一个标号,我们记作a和b,如今我们要将n个人分成两组,进入两个 ...

  10. 在手机中预置联系人/Service Number

    代码分为两部分: Part One 将预置的联系人插入到数据库中: Part Two 保证预置联系人仅仅读,无法被编辑删除(在三个地方屏蔽对预置联系人进行编辑处理:联系人详情界面.联系人多选界面.新建 ...