hdu 1077计算几何

比较简单的计算几何,首先枚举两个在圆上的点,然后数一数多少个点在此圆上,复杂度n^3。但是要注意的是如果这样得到的结果是0,那么还是要输出1,因为至少可以捞一条鱼,这是一个易错点!

/*
 * hdu1077/win.cpp
 * Created on: 2012-10-25
 * Author    : ben
 */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
const int MAXN = 310;
const double eps = 1e-4;
typedef struct MyPoint {
    double x, y;
    MyPoint() {        x = y = 0;    }
    MyPoint(double xx, double yy) {        x = xx;        y = yy;    }
    MyPoint(const MyPoint &p1, const MyPoint &p2) {
        x = (p1.x + p2.x) / 2;
        y = (p1.y + p2.y) / 2;
    }
}MyPoint;
inline double mydistance(const MyPoint &p1, const MyPoint &p2) {
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
inline MyPoint operator-(const MyPoint &p1, const MyPoint &p2) {
    return MyPoint(p1.x - p2.x, p1.y - p2.y);
}
MyPoint points[MAXN];
int N, ans;

inline void getcenter(const MyPoint &p1, const MyPoint &p2, MyPoint &c) {
    MyPoint diff = p1 - p2;
    MyPoint mid(p1, p2);
    double angle;
    double high = mydistance(p1, p2) / 2;
    high = sqrt(1 - high * high);
    if (fabs(diff.x) < eps) {
        c.x = mid.x + high;
        c.y = mid.y;
    } else {
        angle = atan(diff.y / diff.x);
        c.x = mid.x - high * sin(angle);
        c.y = mid.y + high * cos(angle);
    }
}

inline bool myjudge(const MyPoint &p1, const MyPoint &p2) {
    double dis = mydistance(p1, p2);
    return dis <= 1 + eps;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("data.in" , "r", stdin);
#endif
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%d", &N);
        for(int i = 0; i < N; i++) {
            scanf("%lf%lf", &points[i].x, &points[i].y);
        }
        ans = 1;
        MyPoint p;
        for(int i = 0; i < N; i++) {
            for(int j = i + 1; j < N; j++) {
                if(mydistance(points[i], points[j]) > 2 + eps + eps) {
                    continue;
                }
                getcenter(points[i], points[j], p);
                int t = 0;
                for(int k = 0; k < N; k++) {
                    if(myjudge(p, points[k])) {
                        t++;
                    }
                }
                if(t > ans) {
                    ans = t;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

转载于:https://www.cnblogs.com/moonbay/archive/2012/10/25/2740136.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值