poj 2349 Arctic Network(最小生成树的第k大边证明)

题目链接:

  http://poj.org/problem?id=2349

题目大意:

  有n个警戒部队,现在要把这n个警戒部队编入一个通信网络,

  有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部队.

              2,用信号收发器可以链接周围d米以内的部队.

  现在有s个卫星信道,问d最小是多少时能连接全部的警戒部队?

解题思路:

  我是用求最小生成树,记录路径长度,对路径长度排序后,第k长的边就是答案,

  但是队友是用最小k度限制生成树,因为我的方法它证明不了,也推翻不了~~~~,

  最后我下去仔细想了想反证法还是可以证明的。

证明:

  假设:先假设最小生成树的第k大边不是最优解。

  证:现在有一MST,我从中删除了一条第k大的边s,则MST变成了两个联通分支,根据假设存在一条s‘<s,可以使两个联通分支连起来变成联通树MST‘,因为s‘<s,则MST‘<MST,可得出假设不成立!!!!

 1 #include <cmath>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <iostream>
 6 #include <algorithm>
 7 using namespace std;
 8
 9 const int maxn = 500;
10 const int INF = 0x3f3f3f3f;
11 const double Exp = 1e-10;
12
13 struct point
14 {
15     int x, y;
16     int length(point a)
17     {
18         return (a.x - x)*(a.x - x) + (a.y - y)*(a.y - y);
19     }
20 };
21
22 int cost[maxn+10][maxn+10], lowc[maxn+10];
23 int vis[maxn+10], num[maxn+10];
24
25 void init ()
26 {
27     for (int i=0; i<maxn+10; i++)
28         for (int j=0; j<maxn; j++)
29             cost[i][j] = INF;
30 }
31 int prim (int n)
32 {
33     int i, j;
34     memset (vis, 0, sizeof(vis));
35     vis[0] = 1;
36     for (i=0; i<n; i++)
37         lowc[i] = cost[0][i];
38     for (i=1; i<n; i++)
39     {
40         int p, mini = INF;
41         for (j=0; j<n; j++)
42             if (!vis[j] && lowc[j] < mini)
43             {
44                 p = j;
45                 mini = lowc[j];
46             }
47         vis[p] = 1;
48         for (j=0; j<n; j++)
49         {
50             if (!vis[j])
51                 lowc[j] = min(lowc[j], cost[p][j]);
52         }
53     }
54 }
55
56 int main ()
57 {
58     int n, s, p;
59     point P[maxn + 10];
60     scanf ("%d", &n);
61     while (n --)
62     {
63         scanf ("%d %d", &s, &p);
64         for (int i=0; i<p; i++)
65         {
66             scanf ("%d %d", &P[i].x, &P[i].y);
67             for (int j=0; j<i; j++)
68                 cost[i][j] = cost[j][i] = P[i].length(P[j]);
69         }
70         prim (p);
71         sort (lowc, lowc+p, greater<int>());
72         printf ("%.2f\n", sqrt(lowc[s-1]));
73     }
74     return 0;
75 }
时间: 2024-08-09 19:52:41

poj 2349 Arctic Network(最小生成树的第k大边证明)的相关文章

POJ 2349 Arctic Network 最小生成树题解

本题也是使用Prime和Kruskal都可以的最小生成树的题解. 本题一点新意就是:需要除去最大的S-1个距离,因为可以使用卫星覆盖这些距离. 技巧:建图建有向图,速度快点,不用计算两边. 这里使用Prime,因为是稠密图. #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <al

POJ 2349 Arctic Network (最小生成树第K大(小)边)

Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13108   Accepted: 4256 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication tec

poj 2349 Arctic Network (prim算法)

Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10525   Accepted: 3470 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication tec

poj 2349 Arctic Network MST/二分答案

poj 2349 Arctic Network 题目传送 Sol: 方法一: 贪心的想,发现n个点只需要n-1条边即可,求MST即可,再把MST中最大的m-1条边去掉,第m大就是答案. code: #include<string> #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define IL inline #define RG register

POJ 2349 Arctic Network

Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18447   Accepted: 5829 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication tec

POJ 2349 Arctic Network(最下生成树+求第k大边)

题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两个前哨之间的距离不超过D,才能通过无线电进行通信.求出能使所有前哨都能直接或间接通信的最小的D. 解题思路:题目要求使所有前哨都能直接或间接通信,那么相当于使n个点相连,至少需要n-1条边.可以将n个点分为s个团,每个团内部时无限通信,团与团之间通过卫星通信.那么就相当于用s个卫星装置建立s-1条边

POJ 2349 Arctic Network (最小生成树)

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 a

poj 2349 Arctic Network(prime)

Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25165   Accepted: 7751 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are t

poj2349Arctic Network(最小生成树kruscal+第k长的边)

题目链接: 啊哈哈,点我点我 题意: 北极的某区域共有n座村庄( 1 ≤ n ≤ 500 ),每座村庄的坐标用一对整数(x, y)表示,其中 0 ≤ x, y ≤ 10000.为了加强联系,决定在村庄之间建立通讯网络.通讯工具可以是无线电收发机,也可以是卫星设备.所有的村庄都可以拥有一部无线电收发机, 且所有的无线电收发机型号相同.但卫星设备数量有限,只能给一部分村庄配备卫星设备.  不同型号的无线电收发机有一个不同的参数d,两座村庄之间的距离如果不超过d就可以用该型号的无线电收发机直接通讯,d