Transmitters
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4328 | Accepted: 2295 |
Description
In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don't overlap, or at least that they don't conflict. One way of accomplishing this is to restrict a transmitter's coverage area. This problem uses a shielded transmitter that only broadcasts in a semicircle.
A transmitter T is located somewhere on a 1,000 square meter grid. It broadcasts in a semicircular area of radius r. The transmitter may be rotated any amount, but not moved. Given N points anywhere on the grid, compute the maximum number of points that can be simultaneously reached by the transmitter's signal. Figure 1 shows the same data points with two different transmitter rotations.
All input coordinates are integers (0-1000). The radius is a positive real number greater than 0. Points on the boundary of a semicircle are considered within that semicircle. There are 1-150 unique points to examine per transmitter. No points are at the same location as the transmitter.
A transmitter T is located somewhere on a 1,000 square meter grid. It broadcasts in a semicircular area of radius r. The transmitter may be rotated any amount, but not moved. Given N points anywhere on the grid, compute the maximum number of points that can be simultaneously reached by the transmitter's signal. Figure 1 shows the same data points with two different transmitter rotations.
All input coordinates are integers (0-1000). The radius is a positive real number greater than 0. Points on the boundary of a semicircle are considered within that semicircle. There are 1-150 unique points to examine per transmitter. No points are 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 on 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 will be present but indeterminate. Figures 1 and 2 represent the data in the first two example data sets below, though they are on different scales. Figures 1a and 2 show transmitter rotations that result in maximal coverage.
Output
For each transmitter, the output contains a single line with the maximum number of points that can be contained in some semicircle.
Sample Input
25 25 3.5 7 25 28 23 27 27 27 24 23 26 23 24 29 26 29 350 200 2.0 5 350 202 350 199 350 198 348 200 352 200 995 995 10.0 4 1000 1000 999 998 990 992 1000 999 100 100 -2.5
Sample Output
3 4 4 题目大意:就是给定一个圆的圆心和半径,求某个半圆能包含最多的点的个数; 思路:由于圆心和半径都确定,又是180度,这里枚举过一点的直径,然后将其他点(也包括自己点)与圆心的连线构成的向量与该直径做叉积, 就可以用叉积的等于,大于,小于0判断点在直径上,右,左。 这里要记录直径两边的加直径上的点的个数,取最大的。 处理方法:在输入过程中,将所有不在圆外的点删除,对于某些在圆心上的点(虽然题目说明,任意两点都不相同,但是没有说明,不能有点在圆心上)也将其视为在圆外, 但是枚举的点数量的初始值应该加上这些点。 代码如下:/* @author : liuwen */ #include <iostream> #include <cstdio> #include <cstring> #include <climits> //INT_MAX INT_MIN LONG_LONG_MAX LONG_LONG_MIN #include <cstdlib> #include <queue> #include <stack> #include <map> #include <vector> #include <cmath> #include <algorithm> using namespace std; const double eps=1e-10; struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){} }; typedef Point Vector; int dcmp(double x) { if(fabs(x)<eps) return 0; else return x<0?-1:1; } double cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; } bool isIn(double x0,double y0,double r,double x,double y) { if((x-x0)*(x-x0)+(y-y0)*(y-y0)<=r*r) return true; else return false; } Point a[1005]; int main() { //freopen("in.txt","r",stdin); double x0,y0,r,x,y; int T; while(cin>>x0>>y0>>r){ if(r<0) continue; cin>>T; int cnt=0,ans=0; for(int i=0;i<T;i++){ cin>>x>>y; if(isIn(x0,y0,r,x,y)){ if(dcmp(x0-x)==0&&dcmp(y0-y)==0){ ans++; }else{ a[cnt++]=Point(x,y); } } } int init=ans; //初始值 int lnum=init,rnum=init; for(int i=0;i<cnt;i++){ lnum=rnum=init; Vector diamer=Vector(a[i].x-x0,a[i].y-y0); for(int j=0;j<cnt;j++){ int cmp=dcmp(cross(diamer,Vector(a[j].x-x0,a[j].y-y0))); //判断在直径中,右,还是左 if(cmp==0) rnum++,lnum++;//上 else if(cmp>0) rnum++; //右 else lnum++;//左 } ans=max(ans,max(lnum,rnum)); } cout<<ans<<endl; } return 0; }