`
java-mans
  • 浏览: 11385747 次
文章分类
社区版块
存档分类
最新评论

hdu1077已知半径以及圆上2点求圆心 圆圈点的个数

 
阅读更多

Catching Fish

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


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

Author
Ignatius.L
#include <math.h>  
#include <stdio.h>   
const static double  eps = 1e-6;  
struct Point  
{  
    double x,y;  
};  
double distancess(Point a,Point b)  
{  
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);  
}  
Point look_center(Point a,Point b)  //已知半径以及圆上2点求圆心代码:a,b是圆上点
{  
    Point aa,bb,mid;  
    aa.x = b.x-a.x; 
    aa.y = b.y-a.y;  
    mid.x = (a.x+b.x)/2.0;  
    mid.y = (a.y+b.y)/2.0;  
    double dist = distancess(a,mid);
    double c = sqrt(1.0-dist);   //1.0是半径   套用代码时要根据题意改变
  //  if(fabs(aa.y)<eps)  
 //   {  
//       bb.x = mid.x;
 //      bb.y = mid.y+c;            //这几句nop掉的话 加上可以减少时间 不加也能过 不知道是干嘛的
 //   }  
 //   else  
 //   {  
        double ang = atan(-aa.x/aa.y);  
        bb.x = mid.x + c*cos(ang);  
        bb.y = mid.y + c*sin(ang);
 //  }  
    return bb;//用结构体变量bb存储圆心的坐标并返回
}  
int main()  
{  
    int test;  
    Point p[305],a;  
    int n;  
    scanf("%d",&test);  
    while(test--)  
    {  
        scanf("%d",&n);  
        for(int i=0; i<n;i++)  
            scanf("%lf%lf",&p[i].x,&p[i].y);  
  
        int ans = 1;  
        int temp = 0;
        for(i =0;i<n; i++)
            for(int j=i+1;j<n;j++)  
            {     
                if(distancess(p[i],p[j])>4) continue;  
                a = look_center(p[i],p[j]);  
                temp = 0;  
                for(int k=0;k<n;k++)  
                {  
                    if(distancess(a,p[k])<=1.000001) temp++;  
                }  
                if(ans<temp) ans = temp;  
            }  
            printf("%d\n",ans);  
    }  
    return 0;  
}
/*题目大意:
给出一些点坐标,问有一个半径为1的圆,一次最多能圈多小个点。
给定两个点,如里它们的距离大于直径,不必考虑,否则,认为这两个点在某一圆上,计算出圆心坐标,
依次遍历顶点,记录在这个圆里面的点,这个值就是我们要进行判定的值。。。
*/
/*对于本题 我是狗屁不懂 但是有一个很重要的东西
就是已知半径以及圆上2点求圆心 
只要会用这个求圆心的方法即可*/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics