UVALive 2963 Hypertransmission

2963 - Hypertransmission

Time limit: 6.000 seconds

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 inA 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 

Input consists of several datasets. The first line of each dataset contains N - the number of planets in the Galactic Federation (1N1000).
Next N lines contain four integer numbers xiyizi, and pi each and describe the
planets: xiyi, 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.

Ouput

First output D - the maximal possible number of destabilizing planets. After that output non-negative real number R -
the minimal range that hyper-radio transmitters must have so that the number of destabilizing planets is DR 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

题意:每个星球都要造一座广播台,广播台主要有两种,让你选择一个距离d, 以每一个星球为圆心,以d为半径,圆范围内,跟它型号相同的星球数量记为N+(A),包括自己本身,跟它型号不同的记为N-(A), 如果一个星球的N+(A) < N-(A) , 那么这个星球就标记为不稳定的,现在问你最多能使多少个星球为不稳定,并且使d尽可能的小。

思路:很明显的一道dp,因为d肯定是其中两点之间的距离,所以我们可以先算出每两点之间的距离,用一个结构体保存每条边的两个端点和长度,为了节省时间,把这些边从小到大排序,相同的长度的边就可以一起处理。用val[]数组来记录N+(A)和N-(A)的数量,因为N+(A)是要包括自己本身的,所以我们在初始化的时候都把它标记为1,遇到型号相同的就+1,遇到不同的就-1,当val值为负就代表不稳定,为正就为稳定,为了避免重复计算,就规定为-1时为不稳定,为0时为稳定。

代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1010;
int n, val[N];
struct node
{
	int x,y,z;
	int type;
}p[N];

struct Node
{
	int s, t;
	int dis;
	bool operator<(const Node &r) const {
		return dis < r.dis;
	}
}q[N*N/2];

int fd(node a, node b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}

int main()
{
	int i, j;
	while(~scanf("%d", &n))
	{
		for(i = 0; i < n; i ++)
		{
			scanf("%d%d%d%d", &p[i].x, &p[i].y, &p[i].z, &p[i].type);
		}
		int tmp = 0;
		for(i = 0; i < n; i ++)
		{
			val[i] = 1;
			for(j = i + 1; j < n; j ++)
			{
				q[tmp].s = i;
				q[tmp].t = j;
				q[tmp].dis = fd(p[i], p[j]);
				tmp ++;
			}
		}
		sort(q, q + tmp);
		int cnt, ans, d;
		cnt = ans = d = 0;
		for(i = 0; i < tmp; )
		{
			for(j = i; j < tmp && q[j].dis == q[i].dis; j ++)
			{
				if(p[q[j].s].type != p[q[j].t].type)
				{
					if(-- val[q[j].s] == -1)
                    	cnt++;
                    if(-- val[q[j].t] == -1)
                        cnt++;
				}
				else
				{
                    if(++ val[q[j].s] == 0)
                        cnt --;
                    if(++ val[q[j].t] == 0)
                        cnt --;
                }
			}
			if(cnt > ans)
			{
                ans = cnt;
                d = q[i].dis;
            }
            i = j;
		}
		printf("%d\n%.4lf\n", ans, sqrt(d*1.0));
	}
	return 0;
} 
时间: 2024-07-30 07:11:46

UVALive 2963 Hypertransmission的相关文章

uvalive 2963

题意:n个星球上都有一个广播,广播范围是r(和它范围不超过r都可听到广播),广播种类有A和B,如果一个星球可以听到的广播和自身广播不一样的有a个星球,一样的有b个星球,a > b说明这个星球是不稳定的,问给出一个r使不稳定星球尽量多,然后让r尽量少. 题解:先把所有星球之间距离计算出来,然后根据距离排序,把所有距离相同的边放到一起计算不稳定星球的数量,找到最大数量星球,然后再更新r. #include <stdio.h> #include <math.h> #include

UVALive 4848 Tour Belt

F - Tour Belt Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 4848 Description Korea has many tourist attractions. One of them is an archipelago (Dadohae in Korean), a cluster of small islands sca

UVALive 6467 Strahler Order 拓扑排序

这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ 以后能用CIN还是CIN吧 QAQ 贴代码了: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <iostre

UVALive 7077 Little Zu Chongzhi&#39;s Triangles (有序序列和三角形的关系)

这个题……我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了……结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小,想到了回溯每个棍的分组,最多分5组,结果发现超时了……最大是5^12 =  244,140,625,厉害呢…… 后来想贪心,首先想暴力出所有可能的组合,结果发现替换问题是一个难题……最后T T ,我就断片了.. 等看了别人的办法以后,我才发现我忽视了三角形的特性,和把数据排序以后的特点. 如果数据从

Gym 100299C &amp;&amp; UVaLive 6582 Magical GCD (暴力+数论)

题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点时,我们对gcd相同的只保留一个,那就是左端点最小的那个,只有这样才能保证是最大,然后删掉没用的. UVaLive上的数据有问题,比赛时怎么也交不过,后来去别的oj交就过了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&qu

UVALive 6511 Term Project

Term Project Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 651164-bit integer IO format: %lld      Java class name: Main 解题:强连通分量 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1

UVALive 6508 Permutation Graphs

Permutation Graphs Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 650864-bit integer IO format: %lld      Java class name: Main 解题:逆序数 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long l

UVALive 2659+HUST 1017+ZOJ 3209 (DLX

UVALive 2659 题目:16*16的数独.试了一发大白模板. /* * @author: Cwind */ //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <map> #include <algorithm> #include <cstdio> #include <cstring> #include

UVALive 5545 Glass Beads

Glass Beads Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 554564-bit integer IO format: %lld      Java class name: Main Once upon a time there was a famous actress. As you may expect, she played mostly