Transmitters(简单几何)

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;
}
时间: 2024-10-13 13:25:51

Transmitters(简单几何)的相关文章

Python下opencv使用笔记(二)(简单几何图像绘制)

简单几何图像一般包括点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义.图像的一个像素点有1或者3个值,对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值,他们表现出不同的颜色. 那么有了点才能组成各种多边形. (一)首先绘制直线 函数为:cv2.line(img,Point pt1,Point pt2,color,thickness=1,line_type=8 shift=0) 有值的代表有默认值,不用给也行.可以看到这个函数主要接受参数为两个点的坐标,线的颜色

POJ 1473 There&#39;s Treasure Everywhere!(简单几何)

There's Treasure Everywhere! 博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40865611 题目大意: 给你一个字符串,里面有许多的操作,前面的数字是移动的距离,后面的英文表示移动的方向,问最后从远点出发的一个点回落在什么地方以及距离出发点的距离是多少. 解题思路: 题目本身并不是很难,也没有什么坑点,没什么好说的,字符串处理的时候细心一点就行. PS:每组后面需要加一个回车,因为这个PE了一次

简单几何 UVA 11178 Morley&#39;s Theorem

题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /************************************************ * Author :Running_Time * Created Time :2015/10/21 星期三 15:56:27 * File Name :UVA_11178.cpp ************************************************/ #include

HDU 4793 Collision + HDU 4798 Skycity 简单几何

HDU 4793 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793 题意:给一个以(0,0)为圆心半径为R的圆形区域,中间放着一个(0,0)为圆心半径为Rm的圆盘,在坐标(x,y)处(严格在圆形区域外)放着一枚半径为r的硬币,运动方向和速度为(vx,vy),在运动中碰到圆盘时,会按碰撞问题反弹(圆盘是固定不动的),问硬币会在圆形区域里呆多长时间(硬币只要有一点点在圆形区域里就记为硬币在圆形区域内). 思路:首先先计算出硬币在移动过程中如果不与圆盘

hdu5365 简单几何问题

http://acm.hdu.edu.cn/showproblem.php?pid=5365 Problem Description AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and

The Doors 最短路 + 简单几何

The Doors 题目抽象:给你一些点,和一些阻碍连边的线段.问原点到终点最短的几何距离. 分析:预处理见图之后,跑最短路. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 const int INF = 0X5FFFFFFF; 7 const int MS = 1005; 8 const i

CodeForces 703C Chris and Road (简单几何)

题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度.问人到达马路对面的最小时间是多少? 析:这个题是一个简单的分类讨论,很明显只有两种情况,第一种,直接到达w,不会被车撞到,答案就是w/u, 第二种是切着车过去,或者是等车过去再过去,只要枚举车的每个顶点,找到最后通过y轴的点就好,或者根本不会与车相切. 代码如下: #pragma comment(l

osg for android (一) 简单几何物体的加载与显示

1. 首先需要一个OSG for android的环境. (1).NDK 现在Eclipse 对NDK已经相当友好了,已经不需要另外cygwin的参与,具体可以参考 Android NDK开发篇(一):新版NDK环境搭建(免Cygwin,超级快)  (2).osg for android的编译,参考 osg for android学习之一:windows下编译(亲测通过) 建议编译OpenGL ES2版本. 2.然后加载OSG自带的Example:osgAndroidExampleGLES2 (

简单几何(线段相交) POJ 2653 Pick-up sticks

题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /************************************************ * Author :Running_Time * Created Time :2015/10/26 星期一 15:37:36 * File Name :POJ_2653.cpp ************************************************/ #inclu