POJ-2349 Arctic Network (最小生成树)
2017-12-26 23:28
267 查看
Arctic Network
DescriptionThe 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 willin 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.InputThe 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 inkm (coordinates are integers between 0 and 10,000).OutputFor 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
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 23716 | Accepted: 7274 |
1 2 4 0 100 0 300 0 600 150 750Sample Output
212.13
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;struct edge{int from, to, val;bool operator < (const edge& x) const{return val < x.val;}}e[320005];int p[800], x[800], y[800];double dis[320004];int findset(int x){return p[x] == x ? x : p[x] = findset(p[x]);}int main(){int T;scanf("%d", &T);while(T--){int s, u, v, n;scanf("%d %d", &s, &n);for(int i = 1; i <= n; ++i){scanf("%d %d", &x[i], &y[i]);}int num = 0;for(int i = 1; i <= n; ++i){for(int j = i + 1; j <= n; ++j){e[++num].from = i;e[num].to = j;e[num].val = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);}}for(int i = 1; i <= n; ++i){p[i] = i;}sort(e + 1, e + 1 + num);int tot = 0, ans = 0;for(int i = 1; i <= num; ++i){u = findset(e[i].from);v = findset(e[i].to);if(u != v){p[u] = v;++tot;dis[tot] = sqrt(e[i].val);if(tot == n - 1){break;}}}reverse(dis + 1, dis + 1 + tot);printf("%.2f\n", dis[s]);}}/*题意:100个点,求最小生成树,s个卫星,卫星可以代替一条边。思路:最小生成树,改变一下,把最小生成树的所有边存下,用卫星代替长的边即可。*/
相关文章推荐
- poj 2349 Arctic Network 最小生成树
- POJ 2349 Arctic Network 最小生成树题解
- POJ 2349 Arctic Network (最小生成树)
- poj2349——Arctic Network(最小生成树+prim)
- POJ 2349 Arctic Network (最小生成树第K大(小)边)
- POJ - 2349 Arctic Network(最小生成树)
- POJ 2349 Arctic Network(最小生成树中第s大的边)
- poj 2349 Arctic Network 最小生成树,求第k大条边
- POJ 2349 Arctic Network(最小生成树--prime)
- POJ-2349 Arctic Network(最小生成树 prim算法)
- poj 2349 Arctic Network(最小生成树变形)
- POJ 2349 Arctic Network(最小生成树)
- POJ 2349 Arctic Network【最小生成树】
- POJ ~ 2349 ~ Arctic Network (最小生成树)
- Arctic Network (poj 2349 最小生成树)
- poj 2349 (最小生成树)Arctic Network
- POJ 2349 Arctic Network(最小生成树)
- POJ 2349 Arctic Network(最小生成树之Prim)
- poj 2349 Arctic Network 最小生成树第k大边-kruskal
- POJ_2349_Arctic Network(最小生成树)