Transmitters
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4593 | Accepted: 2458 |
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.
![](https://i-blog.csdnimg.cn/blog_migrate/ca2326027acb017a5c2257e43a0606d6.gif)
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
Source
#include<stdio.h>
#include<math.h>
#include<string.h>
#define MAXN 155
const double epsi=1e-10;
inline int sign(const double &x);
inline double sqr(const double &x);
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){
}
Point operator +(const Point &op2) const{
return Point(x+op2.x,y+op2.y);
}
Point operator -(const Point &op2) const{
return Point(x-op2.x,y-op2.y);
}
double operator ^(const Point &op2) const{
return x*op2.y-y*op2.x;
}
double operator *(const Point &op2) const{
return x*op2.x+y*op2.y;
}
Point operator *(const double &d) const{
return Point(x*d,y*d);
}
Point operator /(const double &d) const{
return Point(x/d,y/d);
}
bool operator ==(const Point &op2) const{
return sign(x-op2.x)==0&&sign(y-op2.y)==0;
}
};
inline int sign(const double &x){
if(x>epsi) return 1;//>0
if(x<-epsi) return -1;//<0
return 0;
}
inline double mul(const Point &p0,const Point &p1,const Point &p2){//p0p1与p0p2叉积
return (p1-p0)^(p2-p0);
}
inline double sqr(const double &x){
return x*x;
}
inline double dis2(const Point &p0,const Point &p1){//p0p1平方
return sqr(p0.x-p1.x)+sqr(p0.y-p1.y);
}
inline double dis(const Point &p0,const Point &p1){//p0p1
return sqrt(dis2(p0,p1));
}
Point p[MAXN],cp;
int main(){
double r;
int N;
while(~scanf("%lf%lf%lf",&cp.x,&cp.y,&r),r>=0){
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
int maxi=0,temp=0;
for(int i=0;i<N;i++){
// printf("%lf ~%lf\n",p[i].x,p[i].y);
temp=0;
for(int j=0;j<N;j++){
if(sign(dis(p[j],cp)-r)!=1) //在半径范围内
if(sign(mul(cp,p[i],p[j]))!=-1){
temp++;//如果都是同一个方向
// printf("%lf ~~~%d\n",mul(cp,p[i],p[j]),sign(mul(cp,p[i],p[j])));
}
}
maxi=temp>maxi?temp:maxi;
}
printf("%d\n",maxi);
}
return 0;
}
先判断是否在圆周区域内,
在判断是否在同一个方向,使用向量积p0p1与p0p2,
只要判断大小如果结果是>0则p2在p0p1的顺时针方向
如果结果是<0则p2在p0p1的逆时针方向
如果=0就是共线