码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-08-03 18:45:56      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

传送门

Transmitters

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 5088Accepted: 2686

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


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

解题思路:
PS:最近有点忘记计算几何了,所以做几个简单题目熟悉一下。
首先我们需要找到这个半圆能够覆盖的点,也就是点到圆心的距离 <=; r,然后在这些点的基础上,进行一些操作。就是跑两个循环,然后判断一个点的一边有多少个点(通过叉积来判断),找最大值就行。

My Code

/**
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;
}

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

标签:

原文地址:http://blog.csdn.net/qingshui23/article/details/52106335

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!