POJ-1106 Transmitters解题报告

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
题目链接:http://poj.org/problem?id=1106
题目大意:题目意思很简单,给你圆心坐标和圆半径,以及有限个点,要求你计算出半圆最多能覆盖多少点,
题目思路:我们可以先将不在圆区域内的点先删除,减少后面的比较量,然后我们可以把每个点与圆心的连线作为分割圆的半径,并比较两边的点的数量,存入较多的一边,这样最后比较所有点的最大值即可。关键在于如何知道其他点在此连线的哪一边,这里就用到了叉乘,令一个点为(x,y),将该点与圆心的连线作为分割线,任意的其他点设为(a,b),则容易知道,如果其他点在连线左边,其与圆心的斜率比分割线小,在右边则比分割线大,则有y/x-b/a,即比较y*a-x*b与0的大小,在草稿上计算一下就明白了。
实现代码:
#include<iostream>
using namespace std;
int con(int a,int b,int c,int d)//斜率比较函数,判断在左或是右,或是在同一直线。
{
	return a*b-c*d;
}
struct Point//定义点结构体。
{
	int x;
	int y;
};
int main()
{
	int X,Y,n,x,y,ok,max,i,j,k;
	double r;
	struct Point a[151];
	while(cin>>X>>Y>>r)
	{
		if(r<0)
			break;
		cin>>n;
		for(i=0,k=0;i<n;i++)//输入时只记录在圆内的点。
		{
			cin>>x>>y;
			if( (X-x)*(X-x)+(Y-y)*(Y-y)<=r*r )
			{
				a[k].x=x;
				a[k].y=y;
				k++;
			}
		}
		max=0;
		for(i=0;i<k;i++)
		{
			int cout=1;
			for(j=0;j<k;j++)
				if(j!=i)
				{
					ok=con(a[i].y-Y,a[j].x-X,a[i].x-X,a[j].y-Y);
					if(ok>=0)//在这儿我将同一直线的点归为到了在右边,都一样的。
						cout++;
				}
			if(k-cout>cout)//另一半的点如果较多,则存入另一半的点数。
				cout=k-cout;
			if(cout>max)
				max=cout;
		}
		cout<<max<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值