POJ 1901 | LA 2963 | UVa 1325 - Hypertransmission (思维 扫描)

Hypertransmission
Time Limit: 10000MS Memory Limit: 30000K
Total Submissions: 1477 Accepted: 361 Special Judge

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

4
0 0 0 1
0 1 0 0
1 0 0 0
1 1 0 1

Sample Output

4
1.0000

Source



题意:

给出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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值