题意大体是,给出圆心位置和半径,再给出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
代码:
# 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;
}
转载于:https://blog.51cto.com/7938122/1613316