hdu 1077(单位圆覆盖问题)

Catching Fish

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1741    Accepted Submission(s): 686

Problem Description

Ignatius
likes catching fish very much. He has a fishnet whose shape is a circle
of radius one. Now he is about to use his fishnet to catch fish. All
the fish are in the lake, and we assume all the fish will not move when
Ignatius catching them. Now Ignatius wants to know how many fish he can
catch by using his fishnet once. We assume that the fish can be regard
as a point. So now the problem is how many points can be enclosed by a
circle of radius one.

Note: If a fish is just on the border of the fishnet, it is also caught by Ignatius.

Input

The
input contains several test cases. The first line of the input is a
single integer T which is the number of test cases. T test cases follow.
Each
test case starts with a positive integer N(1<=N<=300) which
indicate the number of fish in the lake. Then N lines follow. Each line
contains two floating-point number X and Y (0.0<=X,Y<=10.0). You
may assume no two fish will at the same point, and no two fish are
closer than 0.0001, no two fish in a test case are approximately at a
distance of 2.0. In other words, if the distance between the fish and
the centre of the fishnet is smaller 1.0001, we say the fish is also
caught.

Output

For each test case, you should output the maximum number of fish Ignatius can catch by using his fishnet once.

Sample Input

4
3
6.47634 7.69628
5.16828 4.79915
6.69533 6.20378
6
7.15296 4.08328
6.50827 2.69466
5.91219 3.86661
5.29853 4.16097
6.10838 3.46039
6.34060 2.41599
8
7.90650 4.01746
4.10998 4.18354
4.67289 4.01887
6.33885 4.28388
4.98106 3.82728
5.12379 5.16473
7.84664 4.67693
4.02776 3.87990
20
6.65128 5.47490
6.42743 6.26189
6.35864 4.61611
6.59020 4.54228
4.43967 5.70059
4.38226 5.70536
5.50755 6.18163
7.41971 6.13668
6.71936 3.04496
5.61832 4.23857
5.99424 4.29328
5.60961 4.32998
6.82242 5.79683
5.44693 3.82724
6.70906 3.65736
7.89087 5.68000
6.23300 4.59530
5.92401 4.92329
6.24168 3.81389
6.22671 3.62210

Sample Output

2
5
5
11

模板题:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
const int N = 300;
struct Point
{
    double x,y;
} p[N];
struct Node
{
    double angle;
    bool in;
} arc[180000];
int n,cnt;
double R;
double dist(Point p1,Point p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
bool cmp(Node n1,Node n2)
{
    return n1.angle!=n2.angle?n1.angle<n2.angle:n1.in>n2.in;
}
void MaxCircleCover()
{
    int ans=1;
    for(int i=0; i<n; i++)
    {
        int cnt=0;
        for(int j=0; j<n; j++)
        {
            if(i==j) continue;
            if(dist(p[i],p[j])>R*2) continue;
            double angle=atan2(p[i].y-p[j].y,p[i].x-p[j].x);
            double phi=acos(dist(p[i],p[j])/2);
            arc[cnt].angle=angle-phi;
            arc[cnt++].in=true;
            arc[cnt].angle=angle+phi;
            arc[cnt++].in=false;
        }
        sort(arc,arc+cnt,cmp);
        int tmp=1;
        for(int i=0; i<cnt; i++)
        {
            if(arc[i].in) tmp++;
            else tmp--;
            ans=max(ans,tmp);
        }
    }
    printf("%d\n",ans);
}
int main()
{
    int tcase;
    scanf("%d",&tcase);
    while(tcase--)
    {
        scanf("%d",&n);
//scanf("%lf",&R);
        R = 1; //此题 R 为 1
        for(int i=0; i<n; i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        MaxCircleCover();
    }
    return 0;
}
时间: 2024-10-08 21:46:00

hdu 1077(单位圆覆盖问题)的相关文章

poj1981Circle and Points(单位圆覆盖最多的点)

链接 O(n^3)的做法: 枚举任意两点为弦的圆,然后再枚举其它点是否在圆内. 用到了两个函数 atan2反正切函数,据说可以很好的避免一些特殊情况 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath&g

HDU 1077 Catching Fish(用单位圆尽可能围住多的点)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1077 Catching Fish Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2636    Accepted Submission(s): 969 Problem Description Ignatius likes catching

poj1981 Circle and Points 单位圆覆盖问题

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Circle and Points Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 6850   Accepted: 2443 Case Time Limit: 2000MS Description You are given N points in the xy-plane. You have a cir

HDU 1077 - Catching Fish

Catching Fish Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1827    Accepted Submission(s): 725 Problem Description Ignatius likes catching fish very much. He has a fishnet whose shape is a c

hdu 1255 矩形覆盖面积(面积交)

http://www.cnblogs.com/scau20110726/archive/2013/04/14/3020998.html 面积交和面积并基本上差不多.在面积并里,len[]记录的是覆盖一次或以上的长度.如果想要知道覆盖两次或以上的长度,可以加入一个len2[]数组. 1.col[rt]>=2 : 说明该区间被覆盖两次或以上,那么长度就可以直接计算,就是该区间的长度 2.先看叶子节点,因为是叶子没有孩子了,所以被覆盖两次货以上的长度就是0(无论col[rt]=1或col[rt]=0都

hdu3982 直线切多边形

题意:有一块蛋糕,上面有一颗cherry.用刀子切n次,求切完之后有cherry的那部分的面积 My solution: 先做一个大矩形,使cake内切于这个大矩形.如图: 然后不断切这个大矩形,每次切割的时候保留与cherry同侧的那部分.最后剩下的就是一个多边形.求该多边形与圆的面积交即可. 在切割的时候如何保证留下来的是与cherry同侧的部分呢?很简单 方法不难,但是一直WA= =.遇到了个奇怪的问题: 对于这组数据: 3 5 2-5 0 5 3-5 0 5 -30 05 2-5 0 5

[转]计算几何模板

Repost 1. 1 #include<vector> 2 #include<list> 3 #include<map> 4 #include<set> 5 #include<deque> 6 #include<queue> 7 #include<stack> 8 #include<bitset> 9 #include<algorithm> 10 #include<functional>

poj2318

题意:把一个矩形划分成n部分,再给出一堆点,求每个部分内落入了多少点 sol attempt1:暴力 注意每个polygon中的点要按笔画的顺序排列好.还有就是有的点可能落在了upper or lower edge,稍微处理一下(ans==1 or 2都算) TLE了 -_-|| 1 #include<vector> 2 #include<list> 3 #include<map> 4 #include<set> 5 #include<deque>

poj3675 求多边形与圆的面积交

题意:给出多边形的顶点坐标.圆的圆心坐标和半径,求面积交 sol:又是模板题啦= = 注意poj的C++好像认不出hypot函数,要稍微改写一下. hypot(double x,double y):即返回sqrt(x*x+y*y)的值 1 #include<vector> 2 #include<list> 3 #include<map> 4 #include<set> 5 #include<deque> 6 #include<queue&g