hdu 1077(单位圆覆盖问题)
2016-06-08 21:20
267 查看
Catching Fish
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1741 Accepted Submission(s): 686
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, you should output the maximum number of fish Ignatius can catch by using his fishnet once.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
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 ; 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; }
相关文章推荐
- 颓废的一年
- 典型用户与场景
- java 直接插入排序代码
- weka
- hdu 2582 f(n)(找规律,素数筛选,优化)
- IRP结构体之Flag成员
- eclipse通过类名,找到所在的jar包
- Java 关于强引用,软引用,弱引用和虚引用的区别与用法
- 如果当年国民党胜利了,中国今天是什么个样子!
- 【Leetcode 86】 Partition List
- xml知识点总结
- spring 登录拦截器
- 多看python原代码
- 【问题】VS2013全版本密钥
- 层序遍历二叉树(C语言+循环队列)
- mysql update 有无索引对比
- HDU 2028 Lowest Common Multiple Plus
- windows游戏编程(一)
- GDI+ 如何绘制圆角矩形(vc++)
- mysql数据库字段类型的选择原则