poj 1106 Transmitters

题意:给定一个点的坐标和一个圆半径,一个整数n,然后n个点坐标,求以给定点所在半圆能包含的最多点的个数;

思路:枚举半圆直径边界,统计该边界一侧的包含点数,更新最大值;

技巧:使用叉积,能方便的判断两向量的夹角是否小于180度;

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const double epsi=1e-10;
const double pi=acos(-1.0);
const int maxn=50005;
struct point{
    double x,y;
    point(double xx=0,double yy=0):x(xx),y(yy){}
    point operator -(const point &op2) const{  //向量相减
        return point(x-op2.x,y-op2.y);
    }
    double operator ^(const point &op2) const{  //两个点向量的叉积
        return x*op2.y-y*op2.x;
    }
};
inline int sign(const double &x){  //判断浮点数正负
    if(x>epsi) return 1;
    if(x<-epsi) return -1;
    return 0;
}
inline double sqr(const double &x){ //平方
    return x*x;
}
inline double mul(const point &p0,const point &p1,const point &p2){  //p0p1与p0p2的叉积
    return (p1-p0)^(p2-p0);
}
inline double dis2(const point &p0,const point &p1){ //p0p1向量模的平方
    return sqr(p0.x-p1.x)+sqr(p0.y-p1.y);
}
inline double dis(const point &p0,const point &p1){  //p0p1的向量模
    return sqrt(dis2(p0,p1));
}
int n;
point p[maxn],cp;
double r;
int main(){
    while(scanf("%lf%lf%lf",&cp.x,&cp.y,&r)&&r>=0){
        scanf("%d",&n);
        int ans=0;
        for(int i=0;i<n;i++) scanf("%lf %lf",&p[i].x,&p[i].y);
        for(int i=0;i<n;i++){  //枚举边界
            int tmp=0;
            for(int j=0;j<n;j++)  //枚举点
                if(sign(dis(p[j],cp)-r)!=1)  //距离小于半径且在边界同一侧
                if(sign(mul(cp,p[i],p[j]))!=-1) tmp++;
            ans=max(ans,tmp);
        }
        printf("%d\n",ans);
    }
    return 0;
}
时间: 2024-12-17 00:20:31

poj 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: 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

先判断是否在圆内,然后用叉积判断是否在180度内.枚举判断就可以了... 感觉是数据弱了.. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const double eps=0.00000001; struct point{ double x,y; }p[1050

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 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4955   Accepted: 2624 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几何分类

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

【转】计算几何题目推荐

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

变量定义错误——库函数中已有对应变量名

G:\GOGOGOGO\POJ\1106-Transmitters\Transmitters.cpp|5|error: 'double y1' redeclared as different kind of symbol| 编写POJ 1106-transmitters 时 加载库函数cmath,同时定义了一个变量y1,codeblocks出现如上错误 原因: 在cmath中有y1的定义,这样会因为重定义而出错.