POJ 1106 Transmitters (computational geometry, cross-product | | Extreme Corner Sort)

Source: Internet
Author: User

Transmitters
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4817 Accepted: 2576

Description

In a wireless network with multiple transmitters sending on the same frequencies, it's often a requirement that signals D On the ' t overlap, or at least that they don ' t conflict. One-of-the-accomplishing this is to restrict a transmitter's coverage area. This problem uses a shielded transmitter the only broadcasts in a semicircle.

A transmitter T is located somewhere on a square meter grid. IT broadcasts in a semicircular area of radius R. The transmitter is rotated any amount and not moved. Given N points anywhere on the grid, compute the maximum number of points that can is simultaneously reached by the TRANSM Itter ' s signal. Figure 1 shows the same data points with the different transmitter rotations.

All input coordinates is integers (0-1000). The radius is a positive real number greater than 0. Points on the boundary of a semicircle is considered within that semicircle. There is 1-150 unique points to examine per transmitter. No points is at the same location as the transmitter.

Input

Input consists of information for one or more independent transmitter problems. Each problem begins with one line containing the (x, y) coordinates of the transmitter followed by the broadcast radius, R. The next line contains the number of points N in the grid, followed by N sets of (x, y) coordinates, one set per line. The end of the input is signalled by a line with a negative radius; The (x, Y) values are present but indeterminate. Figures 1 and 2 represent the data in the first and example data sets below, though they is on different scales. Figures 1a and 2 show transmitter rotations This result in maximal coverage.

Output

For each transmitter, the output contains a, a, and the maximum number of points that can is contained in some SE Micircle.

Sample Input

25 25 3.5725 2823 2727 2724 2326 2324 2926 29350 200 2.05350 202350 199350 198348 200352 200995 995 10.041000 1000999 9989 90 9921000 999100 100-2.5

Sample Output

344

Source

Mid-Central USA 2001 Test instructions is to say that given a fixed center and radius of the semicircle, ask the semicircle to rotate to which angle to cover the most points. When the point on the border is considered also in the semicircle inside. The analysis shows that when the semicircle happens to be rotated at a certain angle, the point is not worse than the corresponding optimal condition when it is on the boundary. So we can first remove those points that are farther from the center of the circle than R. Then enumerate each of the remaining points, connect the center of the circle with the current point, as the radius of the current circle (so get two circles, one to the right of the left, but let's just consider one). See how many points are on the same side of the current semicircle, recorded as Sum, and then update the maximum value of sum from all points. Do not require a polar sort ... Direct enumeration on the line: The method to judge on one side is to use a cross product. Less than 0 counterclockwise greater than 0 clockwise ... Well. All can ...
1 /*************************************************************************2 > File name:code/poj/1106.cpp3 > Author:111qqz4 > Email: [Email protected]5 > Created time:2015 November 09 Monday 09:28 51 seconds6  ************************************************************************/7 8#include <iostream>9#include <iomanip>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <map> -#include <Set> -#include <queue> -#include <vector> +#include <stack> -#include <cctype> + #defineFST First A #defineSEC Second at #defineLson l,m,rt<<1 - #defineRson m+1,r,rt<<1|1 - #defineMS (A,X) memset (A,x,sizeof (a)) - using namespacestd; - Const DoubleEPS = 1e-8; - Const intdx4[4]={1,0,0,-1}; in Const intdy4[4]={0,-1,1,0}; -typedefLong LongLL; to Const intINF =0x3f3f3f3f; + Const  intn=2e4+7; -  the intN; * DoubleR; $ intDBLCMP (Doubled)Panax Notoginseng { -     returnd<-eps?-1:d >EPS; the } + struct Point A { the     Doublex, y; + Point () {} -PointDouble_x,Double_y): $ x (_x), Y (_y) {}; $  -     voidinput () -     { thescanf"%LF%LF",&x,&y); -     }Wuyi      the  -Pointoperator- (ConstPoint &p)Const{ Wu     returnPoint (x-p.x,y-p.y); -     } About     Double operator^(ConstPoint &p)Const{ $     returnx*p.y-y*p.x; -     } -     Doubledis (point P) -     { A     returnsqrt ((x-p.x) * (x-p.x) + (y-p.y) * (yp.y)); +     } the }tmp[n],c,p[n]; - intMain () $ { the #ifndef Online_judge theFreopen ("In.txt","R", stdin); the   #endif the      while(~SCANF ("%lf%lf%lf",&c.x,&c.y,&R)) -     { in     intCNT =0 ; the     if(DBLCMP (R) <=0) Break; thescanf"%d",&n); About      for(inti =0; i < n; i + +) the     { the tmp[i].input (); the         DoubleD =C.dis (Tmp[i]); +         if(DBLCMP (D-r) <=0) -         { the         //P[cnt]=tmp[i];Bayip[cnt].x=tmp[i].x; thep[cnt].y=tmp[i].y; thecnt++; -         } -     } the     intAns =0; the      for(inti =0; I < CNT; i++) the     { the         intsum =1 ; -          for(intj =0; J < CNT; J + +) the         { the         DoubleCross = (C-p[i]) ^ (c-p[j]); the         if(cross>=0&&i!=j)94         { thesum++; the         } the         }98Ans =Max (Sum,ans); About     } -printf"%d\n", ans);101     }102   103    104 #ifndef Online_judge the   #endif106 fclose (stdin);107     return 0;108}
View Code

POJ 1106 Transmitters (computational geometry, cross-product | | Extreme Corner Sort)

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.