ZOJ 1914 Arctic Network (POJ 2349 UVA 10369) MST
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的更多相关文章
- ZOJ 1914 Arctic Network (POJ 2349) MST
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1914 http://poj.org/problem?id=2349 题目大 ...
- POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru
Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...
- ZOJ - 1586 QS Network (Prim)
ZOJ - 1586 QS Network (Prim) #include<iostream> #include<cstring> using namespace std; + ...
- Java实现偶数矩阵(Even Parity, UVa 11464)
偶数矩阵(Even Parity, UVa 11464) 问题描述 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1, 使得每个元素的上.下.左.右的元素(如果存在的话)之和 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- poj 1144 Network(无向图求割顶数)
题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...
- POJ 1966 Cable TV Network(顶点连通度的求解)
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
随机推荐
- ajax处理响应(三)
一旦脚本调用了send方法,浏览器就会在后台发送请求到浏览器.因为请求是在后台处理的,所以Ajax依靠事件来通知你这个请求的进度的进展情况,在上个随笔的里,使用handleResponse函数 ...
- IFC数据模式架构的四个概念层
IFC模型体系结构由四个层次构成, 从下到上依次是 资源层(Resource Layer).核心层(Core Layer).交互层(Interoperability Layer).领域层(Domain ...
- apache2 虚拟机多用户多站点设置 mpm-itk
MPM设置 https://bbs.csdn.net/topics/390479795/ vim /opt/lampp/etc/extra/httpd-ssl.conf vim /opt/lampp/ ...
- Uniform Server
Uniform Server http://www.uniformserver.com/ https://sourceforge.net/projects/miniserver/files/ Unif ...
- js09--函数 call apply
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- 使用gnu automake编译helloworld
使用gnu automake编译helloworld 按照许多介绍automake基本步骤的教程中的说法,我在尝试使用automake编译helloworld示例程序的时候,仍然遇到了几个小坑,所幸后 ...
- golang 逐行读取文件
package main import ( "bufio" "fmt" "io" "os" ) func main() ...
- NuGet 使用及dll管理
NuGet学习笔记(1)——初识NuGet及快速安装使用 作者: 懒惰的肥兔 来源: 博客园 发布时间: 2012-05-20 21:33 阅读: 53168 次 推荐: 33 原文链接 ...
- 【2017 Multi-University Training Contest - Team 9】FFF at Valentine
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6165 [题意] 一张有向图,n个点,m条边,保证没有重边和自环.询问任意两个点能否满足任何一方能够到达另 ...
- Excel查询序列所相应的值-vLoopup函数,求比例分子改变但分母不变
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWV3ZWlvdXlhbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...