POJ 1106 Transmitters (几何覆盖问题)

题目链接:http://poj.org/problem?id=1106

题目:

Transmitters
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4606 Accepted: 2463

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. 

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

题目大意:给出一个半圆的圆心和半径,然后再给N个点的坐标,半圆可以绕半径旋转任意角度,求半圆最多可以覆盖的点的个数是多少。
解题思路:因为圆心是固定的,就很简单了。先把在圆的覆盖范围内的点找出来,再对这些点循环去找对于每个点来说,跟它在同一侧的点的个数,同侧的点判断就用叉积就可以,当叉积>=0的时候就是同一侧的。 最后找出半圆最多可以覆盖的点的个数。

参考代码:

#include<stdio.h>
#include<math.h>
#define max(a,b)  ((a)>(b)?(a):(b))
#define eps 1e-8


int dcmp(double x) {
   return x < -eps ? -1 : x > eps;   //如果x<-eps  那么就返回-1  不然就判断x是否大于eps  是就返回1  不然返回0


struct point{     //定义一个点的结构体 
double x,y;
}p[155];


double distance(point a,point b){      //两点间的距离 
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double chacheng(point a,point b,point c){       //向量叉乘的结果 
return ((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
}
int main(){
point o;
double r;
int n;
while(scanf("%lf%lf%lf",&o.x,&o.y,&r)!=EOF,r>=0){
scanf("%d",&n);
point s;
int m = 0;
for(int i=0;i<n;i++){
scanf("%lf%lf",&s.x,&s.y);
if(dcmp(distance(s,o)-r)<=0){    //先把在半圆内的点存储到数组p里面 
p[m++]=s;

}
int ans=0;
for(int i=0;i<m;i++){
int num = 0;
for(int j=0;j<m;j++){
if(dcmp(chacheng(p[i],p[j],o))>=0){
num++;
}
ans = max(ans,num);

}
printf("%d\n",ans);
}
return 0;
}

已AC。

欢迎广大读者指正~!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值