POJ 1106 Transmitters (简单计算几何)

博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/39297079


Transmitters 


题目大意:给你一个半圆的圆心跟半径,再给你N个点,半圆可以绕圆心旋转任意角度,求半圆最多可以覆盖的点的个数是多少。


解题思路:因为圆心是固定的,就很简单了。先把在圆的覆盖范围内的点找出来,再对这些点循环去找对于每个点来说,跟它在同一侧的点的个数,同侧的点判断就用叉积就可以,当叉积>=0的时候就是同一侧的。


代码如下:

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#define sqr(x) ((x)*(x))
using namespace std;
const double eps = 1e-8;

int dcmp(double x) {
    return x < -eps ? -1 : x > eps;
}

struct Point {
    double x, y;
} P[155];

double Distance(Point a, Point b){
    return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}

double xmult(Point a, Point b, Point c) {
    return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}

int main()
{
    Point o;
    double R;
    int n;
    while(~scanf("%lf%lf%lf", &o.x, &o.y, &R)) {
        if(dcmp(R) < 0) {
            break;
        }
        scanf("%d", &n);
        Point p;
        int m = 0;
        for(int i = 0; i < n; ++i) {
            scanf("%lf%lf", &p.x, &p.y);
            if(dcmp(Distance(p, o)-R) <= 0) {
                P[m++] = p;
            }
        }
        int ans = 0;
        for(int i = 0; i < m; ++i) {
            int num = 0;
            for(int j = 0; j < m; ++j) {
                if(dcmp(xmult(P[i], P[j], o)) >= 0) {
                    num++;
                }
            }
            //printf("p%d = %lf %lf num = %d\n", i, P[i].x, P[i].y, num);
            ans = max(ans, num);
        }
        printf("%d\n", ans);
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值