POJ 1981 Maximum point coverage problem (extreme angle sorting)

Source: Internet
Author: User
Tags acos

Circle and Points
Time Limit: 5000MS Memory Limit: 30000K
Total Submissions: 8346 Accepted: 2974
Case Time Limit: 2000MS

Description

You is given N points in the Xy-plane. You have a circle of radius one and move it in the Xy-plane, so as to enclose as many of the points as possible. Find How many points can is simultaneously enclosed at the maximum. A point was considered enclosed by a circle when it was inside or on the circle.

Fig 1. Circle and Points

Input

The input consists of a series of data sets, followed by a single line is containing a single character ' 0 ', which Indic Ates the end of the input. Each data set is begins with a line containing an integer N, which indicates the number of points in the data set. It is followed by N lines describing the coordinates of the points. Each of the N lines have both decimal fractions X and Y, describing the X-and y-coordinates of a point, respectively. They is given with five digits after the decimal point.

Assume 1 <= N <=, 0.0 <= X <= 10.0, and 0.0 <= Y <= 10.0. No. Points is closer than 0.0001. No points in a data set is approximately at a distance of 2.0. More precisely, for any of the points in a data set, the distance d between the both never satisfies 1.9999 <= D <= 2.00 Finally, no three points in a data set is simultaneously very close to a single circle of radius one. More precisely, let P1, P2, and P3 is any three points in a data set, and D1, D2, and d3 the distances from an arbitrarily Selected the Xy-plane to each of the them respectively. Then it never simultaneously holds that 0.9999 <= di <= 1.0001 (i = 1, 2, 3).

Output

For each data set, print a single line containing the maximum number of points in the data set that can is simultaneously Enclosed by a circle of radius one. No other characters including leading and trailing spaces should is printed.

Sample Input

36.47634 7.696285.16828 4.799156.69533 6.2037867.15296 4.083286.50827 2.694665.91219 3.866615.29853 4.160976.10838 3.460396.34060 2.4159987.90650 4.017464.10998 4.183544.67289 4.018876.33885 4.283884.98106 3.827285.12379 5.164737.84664 4.676934.02776 3.87990206.65128 5.474906.42743 6.261896.35864 4.616116.59020 4.542284.43967 5.700594.38226 5.705365.50755 6.181637.41971 6.136686.71936 3.044965.61832 4.238575.99424 4.293285.60961 4.329986.82242 5.796835.44693 3.827246.70906 3.657367.89087 5.680006.23300 4.595305.92401 4.923296.24168 3.813896.22671 3.622100

Sample Output

25511

Source

Japan 2004 Domestic Test instructions: Given n points, ask how many points can be covered by a single unit circle. Idea: Expand each point into a unit circle, and the intersecting circle will form an intersecting arc,just determine the maximum number of times the arc will be overwritten, because if the arc is overwritten, then the point on the arc is the center of the circle, and it is bound to reach the original point.

N^2 enumeration, save the polar range and the end direction of each arc, then press the top point in front, the bottom point in the back, from large to small to sort the polar angle, scan from the beginning.

If the upper point: ans++ otherwise: ans--, take the ans maximum value.

Code:

1 //#include "bits/stdc++.h"2#include <sstream>3#include <iomanip>4#include"Cstdio"5#include"Map"6#include"Set"7#include"Cmath"8#include"Queue"9#include"Vector"Ten#include"string" One#include"CString" A#include"time.h" -#include"iostream" -#include"stdlib.h" the#include"algorithm" - #defineDB Double - #definell Long Long - #defineVEC vectr<ll> + #defineMt Vectr<vec> - #defineCI (x) scanf ("%d", &x) + #defineCD (x) scanf ("%lf", &x) A #defineCL (x) scanf ("%lld", &x) at #definePi (x) printf ("%d\n", X) - #definePD (x) printf ("%f\n", X) - #definePL (x) printf ("%lld\n", X) - //#define REP (i, X, y) for (int i=x;i<=y;i++) - #defineRep (i, n) for (int i=0;i<n;i++) - Const intN = 1e4+5; in Const intMoD = 1e9 +7; - Const intMoD = mod-1; to Const intINF =0x3f3f3f3f; + ConstDB PI = ACOs (-1.0); - ConstDB EPS = 1e-Ten; the using namespacestd; * structP $ {Panax Notoginseng db x, y; - db ang; the     BOOL inch; + }; A P A[n],b[n]; the db dis (P a,p b) { +     returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); - } $ intCMP (P a,p b) { $     if(A.ang==b.ang)returnA.inch>b.inch;//Upper Point in front -     returnA.ang>B.ang; - } the intMain () - {Wuyi     intN; the      while(SCANF ("%d", &n) = =1, N) -     { Wu         intans=1; -          for(intI=1; i<=n;i++) CD (a[i].x), CD (A[I].Y); About          for(intI=1; i<=n;i++) $         { -             intp=0; -              for(intj=1; j<=n;j++){ -                 if(i==j| | Dis (a[i],a[j]) >2.0+eps)Continue; ADB Ang=atan2 (A[I].X-A[J].X,A[I].Y-A[J].Y);//I at the polar angle of J +DB Tha=acos (DIS (a[i],a[j])/2.0);//Extreme angle Fluctuation range theb[p].ang=ang+tha+2*pi,b[p++].inch=1;//Upper Point -b[p].ang=ang-tha+2*pi,b[p++].inch=0;//Bottom Point $             } theSort (b,b+p,cmp); the             inttmp=1; the              for(intj=0; j<p;j++){ the                 if(B[j].inch==1) tmp++; -                 Elsetmp--; inans=Max (Tmp,ans); the             } the         } About pi (ans); the     } the     return 0; the}

POJ 1981 Maximum point coverage problem (extreme angle sorting)

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.