1106-Transmitters

题意大体是,给出圆心位置和半径,再给出n个其他点的坐标,判断半圆内最多有几个点,落在半圆边缘的点也计算在内,判断半圆不等式写错WA两次

思想是:

1、判断是否在圆内

2、从某一点(在圆内)开始,以这一点和圆心确定的直线为半圆的“底”,计算在此直线“之下”(y1*x-x1*y<=0)且在圆内的点有多少个

Transmitters 


Time Limit: 1000MS


Memory Limit: 10000K


Total Submissions: 4667


Accepted: 2496

Description

In a wireless networkwith multiple transmitters sending on the same frequencies频率, it is often arequirement that signals don‘t overlap重叠、重复, or at least that they don‘tconflict冲突.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. Itbroadcasts in a semicircular area of radius r. The transmitter may be rotated旋转 any amount, but notmoved. Given N points anywhere on the grid, compute the maximum number ofpoints that can be simultaneously reached by the transmitter‘s signal. Figure 1shows the same data points with two different transmitter rotations.

All input coordinates are integers (0-1000). The radius is a positive realnumber greater than 0. Points on the boundary of a semicircle are consideredwithin that semicircle. There are 1-150 unique points to examine pertransmitter. No points are at the same location as the transmitter.

Input

Input consists ofinformation for one or more independent transmitter problems. Each problembegins with one line containing the (x,y) coordinates of the transmitterfollowed by the broadcast radius, r. The next line contains the number ofpoints N on the grid, followed by N sets of (x,y) coordinates, one set perline. 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 thedata in the first two example data sets below, though they are on differentscales. Figures 1a and 2 show transmitter rotations that result in maximalcoverage.

Output

For each transmitter,the output contains a single line with the maximum number of points that can becontained in some semicircle.

SampleInput

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

SampleOutput

3

4

4

Source

Mid-Central USA 2001

代码:

# include <iostream>

# include <cstdlib>

# include <cmath>

using namespace std;

double x1,ya,x2,y2;

struct ele

{

double x;

double y;

bool isCir;

};

void isCir(ele &a,double r)

{

double d;

d=a.x*a.x+a.y*a.y;

if(d<=r*r)

a.isCir=true;

else a.isCir=false;

}

bool isSemicir(int x,int y)

{

double k=(y2-ya)/(x2-x1);

double b=ya-k*x1;

if(k*x-y+b<=0)

return true;

else return false;

}

int cmp(const void* a,const void*b)

{

return (int)(*(ele*)a).x-(int)(*(ele*)b).x;

}

void dis(ele a,double r)

{

double c,d;

c=r/sqrt(1+a.y*a.y/(a.x*a.x));

d=c*(-1);

if(fabs(c-a.x)>=fabs(d-a.x))

{

x1=d;

x2=c;

}

else

{

x1=c;

x2=d;

}

ya=a.y/a.x*x1;

y2=a.y/a.x*x2;

}

int main ()

{

double x,y,a,b;

int i,j,k,s,max,n;

double r;

cin>>x>>y>>r;

while(r>=0)

{

cin>>n;

ele* cor=new ele[n];

for(i=0;i<n;i++)

{

cin>>a>>b;

cor[i].x=a-x;

cor[i].y=b-y;

isCir(cor[i],r);

}

qsort(cor,n,sizeof(cor[0]),cmp);

i=0;

max=0;

while(i<n)

{

if(cor[i].isCir==true)

{

if(cor[i].x==0)

{

x1=x2=0;

if(cor[i].y>=0)

{

ya=r;

y2=-1*r;

}

else

{

y2=r;

ya=-1*r;

}

}

else

{

dis(cor[i],r);

}

for(j=0,s=0;j<n;j++)

{

if(cor[j].isCir==true&&isSemicir(cor[j].x,cor[j].y)==true)

s++;

}

if(s>max)

max=s;

}

i++;

}

cout<<max<<endl;

cin>>x>>y>>r;

}

return 0;

}

时间: 2024-08-07 23:19:05

1106-Transmitters的相关文章

poj 1106 Transmitters (叉乘的应用)

http://poj.org/problem?id=1106 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4488   Accepted: 2379 Description In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don

poj 1106 Transmitters (计算几何,叉积||极角排序)

Transmitters Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4817   Accepted: 2576 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

POJ 题目1106 Transmitters(数学几何)

Transmitters Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4756   Accepted: 2538 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

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

传送门 Transmitters Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5088 Accepted: 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

poj 1106 Transmitters

题意:给定一个点的坐标和一个圆半径,一个整数n,然后n个点坐标,求以给定点所在半圆能包含的最多点的个数: 思路:枚举半圆直径边界,统计该边界一侧的包含点数,更新最大值: 技巧:使用叉积,能方便的判断两向量的夹角是否小于180度: #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const double epsi=1e-10;

【转】计算几何题目推荐

打算转下来好好做计算几何了. 原文地址:http://blog.sina.com.cn/s/blog_49c5866c0100f3om.html 其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠.3.要注意代码的组织,因为计算几何的题目很容易上两百行

[转] POJ几何分类

转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠.3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面大部分是模板.如果代码一片混乱,那么会严重影响做题正确率.4.注意精度控制.5.能用整数的地方尽量用整数,要想到扩大数据的方法(扩大一倍,或扩大sqrt2).因为整数不用考虑浮点误差,而且运算比浮点快. 一.点

POJ Transmitters(计算几何 极角排序啊)

题目链接: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 thi

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 requiremen

Hdu 1106 排序 (atoi函数与 strtok函数的应用

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1106 好久都没刷题了,今天突然特别怀念以前刷题的日子,所以就找了几道水题来做做~~呵呵 在写这篇博客之前呢,已经很明了自己已经大三了,时光匆忙,在还没来得及转过头来,就已经过了两年了大学,原来走了这么远了~~感觉再怎么样,大三还是不敢偷懒~~不过有时候还真是挺迷茫的说实话,在这里呢,真心希望能得到你们各位的建议,只要是对我未来就业有好处的,我都会虚心取纳,(BTW:我是学嵌入式方向的)万分感谢~~~