码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1106 Transmitters

时间:2015-02-27 17:15:51      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:计算几何

把点和圆心连起来作为一个向量,然后判断点在向量右边且在圆内的有多少,再计算出左半边的点有多少,取最大值

#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps=0.001;
struct Point {
    double x,y;
    Point(){}
    Point(double xx,double yy){x=xx;y=yy;}
    Point operator+(Point b){return Point(x+b.x,y+b.y);}
};
Point p[200];
double x,y,r;
int judge(Point a){
    return (a.x-x)*(a.x-x)+(a.y-y)*(a.y-y)<r*r+eps;
}
double xmul(Point p0,Point p1,Point p2){
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif // ONLINE_JUDGE

    int n;
    while(scanf("%lf%lf%lf",&x,&y,&r),r>=eps){
        scanf("%d",&n);
        for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
        int sum=0;
        for(int i=0;i<n;i++) {
            if(judge(p[i])) sum++;
        }
        int ans=0;
        for(int i=0;i<n;i++) {
            int s1=0,s2=0,s;
            for(int j=0;j<n;j++){
                if(xmul(Point(x,y),p[i],p[j])>-eps &&judge(p[j])) s1++;
                if(xmul(Point(x,y),p[i],p[j])<eps &&judge(p[j])) s2++;
            }
            s=max(s1,s2);
            ans=max(s,ans);
        }
        printf("%d\n",ans);

    }
    return 0;
}


POJ 1106 Transmitters

标签:计算几何

原文地址:http://blog.csdn.net/lj94093/article/details/43967775

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!