Quoit Design&&http://acm.hdu.edu.cn/showproblem.php?pid=1007
2012-07-19 15:21
645 查看
求最近点对,模板题。。。。采用的是分治的思想。http://blog.csdn.net/smallacmer/article/details/7763407
[align=left]Problem Description[/align]
Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a
configuration of the field, you are supposed to find the radius of such a ring.
Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered
to be 0.
[align=left]Input[/align]
The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates
of a toy. The input is terminated by N = 0.
[align=left]Output[/align]
For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.
[align=left]Sample Input[/align]
2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
[align=left]Sample Output[/align]
0.71
0.00
0.75
AC代码:
[align=left]Problem Description[/align]
Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a
configuration of the field, you are supposed to find the radius of such a ring.
Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered
to be 0.
[align=left]Input[/align]
The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates
of a toy. The input is terminated by N = 0.
[align=left]Output[/align]
For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.
[align=left]Sample Input[/align]
2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
[align=left]Sample Output[/align]
0.71
0.00
0.75
AC代码:
#include<iostream> #include<string.h> #include<cstdio> #include<cmath> #include<algorithm> #define N 100005 using namespace std; typedef struct { double x; double y; }Node; Node s ,s1 ; bool cmp(Node a,Node b) {return a.x<b.x;} bool cmp1(Node a,Node b) {return a.y<b.y;} double distan(Node a,Node b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double slove(int le,int ri) { if(le+1==ri) return distan(s[le],s[ri]); if(le+2==ri) return min(min(distan(s[le],s[ri]),distan(s[le+1],s[ri])),distan(s[le],s[le+1])); int mid=(le+ri)>>1; double ans=min(slove(le,mid),slove(mid+1,ri)); int cnt=0; for(int i=le;i<=ri;++i) if(s[i].x-s[mid].x<=ans||s[mid].x-s[i].x<=ans) s1[cnt++]=s[i]; sort(s1,s1+cnt,cmp1); for(int i=0;i<cnt;++i) for(int j=i+1;j<cnt;++j) { if(s1[j].y-s1[i].y>=ans) break; ans=min(ans,distan(s1[i],s1[j])); } return ans; } int main() { int n; while(~scanf("%d",&n),n) { for(int i=0;i<n;++i) scanf("%lf%lf",&s[i].x,&s[i].y); sort(s,s+n,cmp); printf("%.2lf\n",slove(0,n-1)/2); }return 0; }
相关文章推荐
- 导弹拦截二&&http://acm.hdu.edu.cn/showproblem.php?pid=1257
- The 36th ACM/ICPC Asia Regional Beijing Site&&http://acm.hdu.edu.cn/showproblem.php?pid=4046
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=791&pid=1001&ojid=0
- Max Sum &&http://acm.hdu.edu.cn/showproblem.php?pid=1003
- http://acm.hdu.edu.cn/showproblem.php?pid=1055&&Color a Tree
- Substrings &&http://acm.hdu.edu.cn/showproblem.php?pid=1238
- 二分查找求函数的区间最小值&&http://acm.hdu.edu.cn/showproblem.php?pid=2899
- Holedox Eating &&http://acm.hdu.edu.cn/showproblem.php?pid=4302
- 找规律。。&&http://acm.hdu.edu.cn/showproblem.php?pid=1097
- http://acm.hdu.edu.cn/showproblem.php?pid=2795&&线段树之求最小区间端点值
- 最小路径覆盖&&http://acm.hdu.edu.cn/showproblem.php?pid=4160
- find the safest road&&http://acm.hdu.edu.cn/showproblem.php?pid=1596
- A C&&http://acm.hdu.edu.cn/showproblem.php?pid=1570
- Happy 2004&&http://acm.hdu.edu.cn/showproblem.php?pid=1452
- I NEED A OFFER! &&http://acm.hdu.edu.cn/showproblem.php?pid=1203
- To The Max &&http://acm.hdu.edu.cn/showproblem.php?pid=1081
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=963&pid=1019&ojid=1
- Text Reverse&&http://acm.hdu.edu.cn/showproblem.php?pid=1062
- Trouble&&http://acm.hdu.edu.cn/showproblem.php?pid=4334
- 完数 &&http://acm.hdu.edu.cn/showproblem.php?pid=1406