您的位置:首页 > 其它

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

2015-11-09 09:59 555 查看
Transmitters

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 4817Accepted: 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 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.

/*************************************************************************
> File Name: code/poj/1106.cpp
> Author: 111qqz
> Email: rkz2013@126.com
> Created Time: 2015年11月09日 星期一 09时28分51秒
************************************************************************/

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<stack>
#include<cctype>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
typedef long long LL;
const int inf = 0x3f3f3f3f;
const  int N=2E4+7;

int n;
double r;
int dblcmp( double d)
{
return d<-eps?-1:d>eps;
}
struct point
{
double x,y;
point(){}
point(double _x,double _y):
x(_x),y(_y){};

void input()
{
scanf("%lf %lf",&x,&y);
}

point operator - (const point &p)const{
return point(x-p.x,y-p.y);
}
double operator ^(const point &p)const{
return x*p.y-y*p.x;
}
double dis(point p)
{
return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
}tmp
,c,p
;
int main()
{
#ifndef  ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
while (~scanf("%lf %lf %lf",&c.x,&c.y,&r))
{
int cnt = 0 ;
if (dblcmp(r)<=0) break;
scanf("%d",&n);
for ( int i = 0 ;i  < n ; i ++)
{
tmp[i].input();
double d =c.dis(tmp[i]);
if (dblcmp(d-r)<=0)
{
//p[cnt]=tmp[i];
p[cnt].x=tmp[i].x;
p[cnt].y=tmp[i].y;
cnt++;
}
}
int ans = 0;
for ( int i = 0 ; i < cnt ; i++)
{
int sum = 1 ;
for ( int j = 0 ; j < cnt ; j++)
{
double cross = (c-p[i])^(c-p[j]);
if (cross>=0&&i!=j)
{
sum++;
}
}
ans = max(sum,ans);
}
printf("%d\n",ans);
}

#ifndef ONLINE_JUDGE
#endif
fclose(stdin);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: