您的位置:首页 > 其它

POJ 1106 Transmitters(计算几何:叉积)

2016-08-03 18:40 627 查看
传送门

Transmitters

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 5088Accepted: 2686
DescriptionIn 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.

InputInput 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. OutputFor 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
SourceMid-Central USA 2001

题目大意:

给你一个半圆的圆心坐标 (x,y)(x,y) 和 半径 rr 和 nn 个点 ,然后让你求可以旋转这个半圆(只能绕着圆心旋转)能够覆盖的最多的点的个数。

解题思路:

PS:最近有点忘记计算几何了,所以做几个简单题目熟悉一下。

首先我们需要找到这个半圆能够覆盖的点,也就是点到圆心的距离 <=;<=; r,然后在这些点的基础上,进行一些操作。就是跑两个循环,然后判断一个点的一边有多少个点(通过叉积来判断),找最大值就行。

MyMy CodeCode:

/**
2016 - 08 - 03 下午
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
struct Point
{
double x, y;
}a[MAXN];
double dis(Point a, Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double Cross(Point a, Point b, Point c)///向量ab X ac
{
Point ab, ac;
ab.x = b.x - a.x, ab.y = b.y - a.y;
ac.x = c.x - a.x, ac.y = c.y - a.y;
return ab.x*ac.y - ab.y*ac.x;
}
int main()
{
double r;
Point R, tmp;
while(cin>>R.x>>R.y>>r)
{
if(r < 0)
break;
int n, cnt = 0, ans = 0;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>tmp.x>>tmp.y;
double d = dis(tmp, R);
if(d <= r*r)
{
a[cnt].x = tmp.x;
a[cnt++].y = tmp.y;
}
}
for(int i=0; i<cnt; i++)
{
int sum = 1;
for(int j=0; j<cnt; j++)
{
if(i == j)
continue;
if(Cross(R,a[i],a[j]) >= 0)
sum++;
}
if(ans < sum)
ans = sum;
}
///cout<<"ans = ";
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: