Transmitters(简单几何)

该博客详细介绍了POJ 1106题目的解决方案,主要涉及数学和几何知识。内容包括题目的描述、输入输出格式以及样例分析,适合对算法和几何感兴趣的读者深入研究。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Transmitters
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4617 Accepted: 2468

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


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

Mid-Central USA 2001

题目意思: 在一个二维平面上,有一个半圆和一些点,半圆可以绕圆心以任意方向旋转,问它最多可以包含几个点;

意解: 首先筛除掉点在圆外的点,把在圆内的点放进p数组,然后极角排序,从小到大;最后确定一个起始点,做半圆,求出包含的点;

AC代码:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
const int M = 500;
const double pi = acos(-1.0);
double p[M];
const double eps=1e-8;

double pow1(double a,double b)
{
    return (a - b) * (a - b);
}

double dist(double x1,double y1,double x2,double y2)
{
    return pow1(y2,y1) + pow1(x2,x1);
}

double Atan2(double x1,double y1,double x2,double y2)
{
    double x = x2 - x1;
    double y = y2 - y1;
    return atan2(y,x);//求出极角
}

int main()
{
   // freopen("in","r",stdin);
    double a,b,r,x,y;
    while(~scanf("%lf %lf %lf",&a,&b,&r) && r > eps)
    {
        int m,to,Max;
        scanf("%d",&m);
        to = Max = 0;
        while(m--)
        {
            scanf("%lf %lf",&x,&y);
            if(dist(x,y,a,b) > r * r) continue;
            p[to++] = Atan2(a,b,x,y);
            if(p[to - 1] < eps) p[to - 1] += 2 * pi;
        }
        sort(p,p + to);
        for(int i = to; i < to * 2; i++)
        {
            p[i] = p[i - to]+2*pi; //方便下面的处理;
        }
        for(int i = 0; i < to; i++)
        {
            int t = 1;
            for(int j = i + 1; j < to * 2; j++)
            {
                double ang=p[j]-p[i];
                if(ang>pi) break;
                t++;
            }
            Max = max(Max, t);
        }
        printf("%d\n",Max);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值