poj 2349 Arctic Network
http://poj.org/problem?id=2349
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 12544 | Accepted: 4097 |
Description
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Input
Output
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
题目大意:有n个哨站,s个卫星频道,有卫星频道的哨站之间的距离可以忽略, 两个哨站之间只有在距离不超过D时才能联络,求D
n个哨站有n - 1条边,s个卫星频道有s - 1条边,用s - 1条边去替换哨站中的边,之后再在哨站连接的边中找最大的边
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#define INF 0x3f3f3f3f
#define max(a, b)(a > b ? a : b)
#define min(a, b)(a < b ? a : b)
#define N 510 using namespace std; struct st
{
int x, y;
} node[N]; double G[N][N], dist[N];
int n;
bool vis[N]; void Init()
{
int i, j;
memset(vis, false, sizeof(vis));
for(i = ; i < n ; i++)
{
for(j = ; j < n ; j++)
{
if(i == j)
G[i][j] = ;
G[i][j] = G[j][i] = INF;
}
}
} void prim(int s)
{
int index, i, j;
double Min;
for(i = ; i < n ; i++)
dist[i] = G[s][i];
vis[s] = true;
for(i = ; i < n ; i++)
{
Min = INF;
for(j = ; j < n ; j++)
{
if(!vis[j] && dist[j] < Min)
{
Min = dist[j];
index = j;
}
}
vis[index] = true;
for(j = ; j < n ; j++)
{
if(!vis[j] && dist[j] > G[index][j])
dist[j] = G[index][j];
}
}
} int cmp(const void *a, const void *b)
{
return *(double *)a > *(double *)b ? : -;
}//double类型快排,因为这wa了很多次 int main()
{
int i, j, s, t;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &s, &n);
Init();
for(i = ; i < n ; i++)
scanf("%d%d", &node[i].x, &node[i].y);
for(i = ; i < n ; i++)
{
for(j = ; j < n ; j++)
{
G[i][j] = G[j][i] = sqrt((node[i].x - node[j].x) * (node[i].x - node[j].x) + (node[i].y - node[j].y) * (node[i].y - node[j].y));
}
}
prim();
qsort(dist, n, sizeof(dist[]), cmp);
printf("%.2f\n", dist[n - s]);
}
return ;
}
poj 2349 Arctic Network的更多相关文章
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- POJ 2349 Arctic Network(最小生成树中第s大的边)
题目链接:http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to c ...
- POJ 2349 Arctic Network(最小生成树+求第k大边)
题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...
- poj 2349 Arctic Network(最小生成树的第k大边证明)
题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...
- poj 2349 Arctic Network(prime)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25165 Accepted: 7751 Description The ...
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...
- POJ 2349 Arctic Network(贪心 最小生成树)
题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...
随机推荐
- 什么是LBS?地理位置服务
做微信开发中必有的LBS,查了下复制过来做个了解. 关键字:定位 服务 基于位置的服务,是指通过电信移动运营商的无线电通讯网络或外部定位方式,获取移动终端用户的位置信息,在GIS平台的支持下,为用户提 ...
- Oracle Create DBLink
DROP PUBLIC DATABASE LINK ORA11G_DBLINK; CREATE PUBLIC DATABASE LINK ORA11G_DBLINKCONNECT TO SYS ...
- 函数buf_page_create
/********************************************************************//** Initializes a page to the ...
- GridView CommandArgument 绑定多个参数
我们在使用GridView的时候 有时会需要绑定多个参数 <asp:GridView ID="gvwVoxListAll" runat="server" ...
- 自定义View,圆形头像
1. 效果图 2. xml中 <com.etoury.etoury.ui.view.CircleImg android:id="@+id/user_info_head_img" ...
- HDU 4635 Strongly connected (强连通分量)
题意 给定一个N个点M条边的简单图,求最多能加几条边,使得这个图仍然不是一个强连通图. 思路 2013多校第四场1004题.和官方题解思路一样,就直接贴了~ 最终添加完边的图,肯定可以分成两个部X和Y ...
- 【C#学习笔记】调用C++生成的DLL
首先用vs2010建立win32项目,选择dll和空项目. 头文件add.h extern "C" __declspec(dllexport) int add(int a,int ...
- POJ 1833 排列
题意: 给你某个排列 求从下一个排列开始的第k个排列如果是最后一个排列 则下一个排列为1 2 3 ... n// 1 用stl 里面的 next_permutation// 2 用生成下一个排列算法/ ...
- Oracle 介绍 (未完待续)
关键字含义 1. DML.DDL.DCL DML----Data Manipulation Language 数据操纵语言例如:insert,delete,update,select(插入.删除.修改 ...
- Oracle 存储过程的创建,及触发器调用存储过程
一.创建存储过程 1.存储过程写法 create or replace procedure HVM_BYQ_TJ --变压器统计信息--->入库 (id in number) as begin ...