poj 2349 Arctic Network
来源:互联网 发布:拼豆制作软件 编辑:程序博客网 时间:2024/06/08 11:21
Arctic Network
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 23234 Accepted: 7139
Description
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.
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
The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).
Output
For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
题意: 有m个卫星和n个哨岗,装卫星的村庄可以自由联络不受限制,其余n-m个村庄只能通过radio连接,为了方便维护每个radio的接收范围都是一致的,求每个radio的最小范围。
做法: n个哨岗存在n-1条边,用prime算法跑一下最小生成树,开一个数组存一下每条边的长度,然后用卫星替代最长的边,剩下的边中最长的即为所求。
这题写完之后怎么交都是WA,搞了半天最后才知道是输出的问题,在G++下提交double 格式是%f,下面附一张区别的图
#include <algorithm>#include <stdio.h>#include <string.h>#include <cmath>using namespace std;const int maxn = 550;double edge[maxn][maxn];double lowcost[maxn];bool vis[maxn];double length[maxn];double INF = 1000000000;int n,m;struct node{ double x,y;}a[maxn];void prim(int num){ int p = 0; vis[num] = 1; for(int i = 1; i <= n; i++) { lowcost[i] = edge[num][i]; } for(int i = 1; i < n; i++) { double minn = INF; int temp; for(int j = 1; j <= n; j++) { if(vis[j] == 0 && lowcost[j] < minn) { minn = lowcost[j]; temp = j; } } vis[temp] = 1; length[p++] = minn; for(int j = 1; j <= n; j++) { if(lowcost[j] > edge[temp][j]) { lowcost[j] = edge[temp][j]; } } } sort(length,length+p); printf("%.2f\n",length[p-m]);}int main(){ int t; scanf("%d",&t); while(t--) { memset(vis,0,sizeof(vis)); scanf("%d%d",&m,&n); for(int i = 1; i <= n; i++) { scanf("%lf%lf",&a[i].x,&a[i].y); } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { edge[i][j] = sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y)); } } prim(1); } return 0;}
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- poj 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- POJ-2349-Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- Poj 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349-Arctic Network
- poj 2349 Arctic Network
- 2017_10_13 Shell&基本数据类型
- PAT——1040. 有几个PAT
- 【20171014】python_语言设计(9)交互式图形编程
- Windows7的基础上安装CentOS双系统
- python2.7 MySQLdb库的安装
- poj 2349 Arctic Network
- 静态方法:无法在静态上下文中引用非静态
- python学习:列表
- package.json 详解
- 阿里云CentOS7中安装Docker
- PAT——1033. 旧键盘打字
- hdu 3926 hand in hand 同构图
- lua table to string
- package.json和config.js有什么关联么