Uvalive 2963 Hypertransmission

Source: Internet
Author: User
Tags integer numbers

2963-hypertransmission

Time limit:6.000 seconds

Description

The president of the Galactic Federation has recently decided, all planets of the galaxy must establish Hyper-radio CE Nters to broadcast their programs. To ensure the process, the Government have signed the contract with well known Hyper-radio equipment manufacturer Trojan Ho RSE LTD. By the terms of this contract the company have to provide N hypertransmitters, one for each planet of the Federation.

It is known this there is both main political movements in the Galaxy:industrialism and ecologism. On each planet of the galaxy one of these movements have the the majority. It is clear that after establishing the Hyper-radio station in the planet, the political programs of the station would supp ORT the movement that have the majority on this planet.

R  parsecs from it. Since The company director was actually the agent of the Dark Empire, he wants to Choose  R  in Such a, 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 an D 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 , the number D of destabilizing planets is maximal possible. Since increasing transmitter ' s range requires more resources for it manufacturing, you must find the smallest possible r maximizing D.


Input  

Input consists of several datasets. The first line of each dataset containsN-The number of planets in the galactic Federation(1N). NextNLines contain four integer numbers xi, yi, zi, and Pi each and describe the planets: xi, yi, and ziSpecify the coordinates of the planet in space, pi = 0If the industrialists has the majority on the planet and pi = 1If the ecologists has the majority. All coordinates don't exceed by their absolute value. No. Planets occupy the same point.

Ouput

First output D -The maximal possible number of destabilizing planets. After, output non-negative real number R -the minimal range that Hyper-radio transmitters must has so that The number of destabilizing planets is D. R must be accurate within 10-4 of the correct answer.


Sample Input

40 0 0 10 1 0 01 0 0 01 1 0 1


Sample Output  

41.0000

Test instructions: Every planet has to build a radio station, there are two main types of broadcasting stations, allowing you to choose a distance of D, the center of each planet, a radius of D, the circle range, and the number of planets with the same model as n+ (a), including itself, with its model is a different record n (a), if a planet n+ (a) < n (A), then the planet is marked as unstable, and now asks how many planets you can make to be unstable and make D as small as possible.

Idea: Obviously a DP, because D is definitely the distance between two points, so we can figure out the distance between each two points, with a structure to save the two endpoints and length of each edge, in order to save time, these edges from small to large order, the same length of the edge can be processed together. Use the val[] array to record the number of n+ (a) and N (a), because n+ (a) is to include itself, so we are initializing it to mark it as 1, encountered the same model number 1, encountered different on-1, when the Val value is negative to represent the instability, is just for stability, In order to avoid repeated calculations, it is stated that 1 is unstable and 0 is stable.

The code is as follows:

#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, &am P;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;}


Uvalive 2963 Hypertransmission

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.