POJ 1901 | LA 2963 | UVa 1325 - Hypertransmission (思维 扫描)
2014-07-04 12:09
405 查看
Hypertransmission
Description
The president of the Galactic Federation has recently decided that all planets of the galaxy must establish hyper-radio centers to broadcast their programs. To ensure the process, the government has signed the contract with well known hyper-radio equipment
manufacturer Trojan Horse Ltd. By the terms of this contract the company has to provide N hypertransmitters, one for each planet of the Federation.
It is known that there are two main political movements in the galaxy: industrialism and ecologism. On each planet of the galaxy one of these movements has the majority. It is clear that after establishing the hyper-radio station on the planet, the political
programs of the station will support the movement that has the majority on this planet.
All transmitters supplied by Trojan Horse Ltd will have the same range, so hyper-radio programs from each planet will be heard at the distance not exceeding R parsecs from it. Since the company director is actually the agent of the Dark Empire, he wants to
choose R in such a way, that it would destabilize the political situation in the Galactic Federation.
More precisely, for each planet A let N+(A) be the number of planets where the same political movement as in A has the majority and hyper-radio programs from A are received, including A itself. Similarly, let N-(A) be the number of planets
where the other political movement has the majority and hyper-radio programs from A are received. The planet A is called destabilizing if N+(A) < N-(A).
Your task is to choose such R that the number D of destabilizing planets is maximal possible. Since increasing transmitter's range requires more resources for its manufacturing, you must find the smallest possible R maximizing D.
Input
The first line of input contains N -- the number of planets in the Galactic Federation (1 <= N <= 1000). Next N lines contain four integer numbers xi, yi, zi, and pi each and describe the planets: xi, yi, and zi specify the coordinates of the planet in space,
pi = 0 if the industrialists have the majority on the planet and pi = 1 if the ecologists have the majority. All coordinates do not exceed 10 000 by their absolute value. No two planets occupy the same point.
Output
First output D -- the maximal possible number of destabilizing planets, and then followed on the second line by a non-negative real number R -- the minimal range that hyper-radio transmitters must have so that the number of destabilizing planets is D. R must
be accurate within 10-4 of the correct answer.
Sample Input
Sample Output
Source
Northeastern Europe 2003
题意:
给出n个星球的坐标(x, y, z)和广播类型(每个星球都会发广播,类型A/B),求一个广播距离范围R,使得不稳定的星球数量最多,在这个基础上R应该尽量小。一个星球不稳定是指 在他收听到的广播中,Na<Nb Na是与自己广播类型相同的数量 Nb是与自己广播类型不同的数量
思路:
这个题比较有意思,首先,最后的R肯定是所有距离中的一个,刚开始的暴力想法是枚举每一个R,然后找出不稳定星球数。这样就是O(n^3) 。后来网上看的题解,因为一条边只会影响两个点,根据长度从小到大枚举R=每条边,比如R=5 变为 R=6这个只需要在R=5的基础上面维护一下R=6的星球的收听相同节目数量
问题:
如果都广播相同类型节目,那么R就是0!
Time Limit: 10000MS | Memory Limit: 30000K | |||
Total Submissions: 1477 | Accepted: 361 | Special Judge |
The president of the Galactic Federation has recently decided that all planets of the galaxy must establish hyper-radio centers to broadcast their programs. To ensure the process, the government has signed the contract with well known hyper-radio equipment
manufacturer Trojan Horse Ltd. By the terms of this contract the company has to provide N hypertransmitters, one for each planet of the Federation.
It is known that there are two main political movements in the galaxy: industrialism and ecologism. On each planet of the galaxy one of these movements has the majority. It is clear that after establishing the hyper-radio station on the planet, the political
programs of the station will support the movement that has the majority on this planet.
All transmitters supplied by Trojan Horse Ltd will have the same range, so hyper-radio programs from each planet will be heard at the distance not exceeding R parsecs from it. Since the company director is actually the agent of the Dark Empire, he wants to
choose R in such a way, that it would destabilize the political situation in the Galactic Federation.
More precisely, for each planet A let N+(A) be the number of planets where the same political movement as in A has the majority and hyper-radio programs from A are received, including A itself. Similarly, let N-(A) be the number of planets
where the other political movement has the majority and hyper-radio programs from A are received. The planet A is called destabilizing if N+(A) < N-(A).
Your task is to choose such R that the number D of destabilizing planets is maximal possible. Since increasing transmitter's range requires more resources for its manufacturing, you must find the smallest possible R maximizing D.
Input
The first line of input contains N -- the number of planets in the Galactic Federation (1 <= N <= 1000). Next N lines contain four integer numbers xi, yi, zi, and pi each and describe the planets: xi, yi, and zi specify the coordinates of the planet in space,
pi = 0 if the industrialists have the majority on the planet and pi = 1 if the ecologists have the majority. All coordinates do not exceed 10 000 by their absolute value. No two planets occupy the same point.
Output
First output D -- the maximal possible number of destabilizing planets, and then followed on the second line by a non-negative real number R -- the minimal range that hyper-radio transmitters must have so that the number of destabilizing planets is D. R must
be accurate within 10-4 of the correct answer.
Sample Input
4 0 0 0 1 0 1 0 0 1 0 0 0 1 1 0 1
Sample Output
4 1.0000
Source
Northeastern Europe 2003
题意:
给出n个星球的坐标(x, y, z)和广播类型(每个星球都会发广播,类型A/B),求一个广播距离范围R,使得不稳定的星球数量最多,在这个基础上R应该尽量小。一个星球不稳定是指 在他收听到的广播中,Na<Nb Na是与自己广播类型相同的数量 Nb是与自己广播类型不同的数量
思路:
这个题比较有意思,首先,最后的R肯定是所有距离中的一个,刚开始的暴力想法是枚举每一个R,然后找出不稳定星球数。这样就是O(n^3) 。后来网上看的题解,因为一条边只会影响两个点,根据长度从小到大枚举R=每条边,比如R=5 变为 R=6这个只需要在R=5的基础上面维护一下R=6的星球的收听相同节目数量
问题:
如果都广播相同类型节目,那么R就是0!
#include <cstdio> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <string> #include <map> #include <cmath> #include <queue> #include <set> using namespace std; //#define WIN #ifdef WIN typedef __int64 LL; #define iform "%I64d" #define oform "%I64d\n" #else typedef long long LL; #define iform "%lld" #define oform "%lld\n" #endif #define S64I(a) scanf(iform, &(a)) #define P64I(a) printf(oform, (a)) #define FOR(i, s, t) for(int (i)=(s); (i)<(t); (i)++) const int INF = 0x3f3f3f3f; const double eps = 10e-9; const double PI = (4.0*atan(1.0)); const int maxn = 1000 + 20; struct Node { int x, y, z, p; }; struct Edge { int s, e, d; }; int n, num; Node A[maxn]; Edge edges[maxn*maxn]; int tmpP[maxn]; bool edgeCmp(Edge a, Edge b) { return a.d < b.d; } int getDis(int a, int b) { return (A[a].x-A[b].x)*(A[a].x-A[b].x) + (A[a].y-A[b].y)*(A[a].y-A[b].y) + (A[a].z-A[b].z)*(A[a].z-A[b].z); } int main() { while(scanf("%d", &n) != EOF) { for(int i=0; i<n; i++) scanf("%d%d%d%d", &A[i].x, &A[i].y, &A[i].z, &A[i].p); num = 0; for(int i=0; i<n; i++) { tmpP[i] = 1; for(int j=i+1; j<n; j++) { edges[num].s = i; edges[num].e = j; edges[num++].d = getDis(i, j); } } sort(edges, edges+num, edgeCmp); int maxP = 0; int minR = 0; int curP = 0; int i = 0; while(i < num) { int j = i; while(j < num && edges[j].d == edges[i].d) { int s = edges[j].s; int e = edges[j].e; if(A[s].p != A[e].p) { if(--tmpP[s] == -1) curP++; if(--tmpP[e] == -1) curP++; } else { if(++tmpP[s] == 0) curP--; if(++tmpP[e] == 0) curP--; } j++; } if(curP > maxP) { maxP = curP; minR = edges[i].d; } i = j; } printf("%d\n%.4lf\n", maxP, sqrt(minR*1.0)); } return 0; }
相关文章推荐
- UVaLive LA 4356 - Fire-Control System (扫描法 思维)
- UVa 1325 Hypertransmission 解题报告(扫描线)
- UVaLive LA 5052 UVa 1481 - Genome Evolution (很巧妙的思维)
- poj - 1308 - Is It A Tree?(Uva - 615, hdu - 1325)
- LA-2523 & POJ-1325 & HDOJ-1150 Machine Schedule 解题报告
- poj 1017 && uva 311 && la 5526
- poj 1042 && uva 757 && la 5422
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
- HDU1318 POJ1590 UVA401 ZOJ1325 Palindromes【回文+水题】
- [poj 1901] Hypertransmission:扫描法,适度暴力
- poj 1873 && uva 811 && la 5211
- LA 2963 超级传输(扫描)
- UVA 1325 - Hypertransmission(扫描方法)
- LA 3708 && POJ 3154 Graveyard (思维)
- poj 1328 && uva 1193 && la 2519
- POJ 1469 - 排列组合的思维..
- POJ 1325 Machine Schedule
- poj 1011/uva 307【经典dfs+超强剪枝+记忆化搜索】
- POJ1989 The Cow Lineup——贪心+扫描技巧
- poj 1325 Machine Schedule 二分图最小点覆盖=最大匹配