传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1007
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2107
【其实之前是在ZOJ上做的,无意中开杭电第一页就看到题目名字一样就戳进去了发现就是一样的2333贴的是杭电上复制来的因为杭电娘的排版看着萌萌哒!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Problem Description
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.
Input
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.
Output
For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.
Sample Input
2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
Sample Output
0.71
0.00
0.75
先扯一下我放假回家都干了些什么 && 要干什么吧……
我13号晚上到的家,刚回家吃完饭差不多就死床上了那天什么都没干2333【除了玩手机!
14号我去和高中基友逛街轧马路逛公园玩过山车去了2333晚上回来依旧死在床上
15号早上7点醒来,外边大暴雨+雷电【看手机之后看到了暴雨橙色预警和雷电橙色预警不要在意这些细节,然后继续睡一直睡到了中午QAQ下午被麻麻拖出门了然后就没有然后了【外加安慰我复读了一年考得还不错但是填志愿没填好被退档的基友 && 帮想补录的事
16号 就今天了,没出门 抱着《算法设计与分析基础》这本书看(其实前几天也有看一点,但没今天多)【这本书感觉真的好棒啊QAQ【尤其是对于我这种渣渣来说!【其实还看了几集真假学园2333【讲什么?【一群萌妹纸打架的故事!,昨天看到可以用蛮力法做最近对立马找了一题果然毫不大意的T了QAQ然后直接往后翻用分治法做才过了。。
17号~22号:和麻麻去九寨沟旅游,不敢带电脑2333麻麻说 拿手机去玩就行了难道你旅游还要打代码么! QAQ我真的想这么做啊……【一想到四川就想找frog学姐面基去啊QAQ可惜学姐去工作了……
23号~30号:社会实践,应该是不带电脑了 每天拍照采访写稿子大概没空而且也不方便……
30号~8.1:没什么突发情况的话能空出两天时间【好吧就这两天了也没别的时间了。。,会和高中的两个基友去海边玩
8.2:凌晨火车回厦门
8.3早上到厦门
8.4开始:lw老师的 个性化指导 2333不知道是什么呢~【姑且算是集训?【嘛。。其实没有多少人
8.15:厦门金海豚第七届国际动漫节!谁都不要拦着我!那天虽然也要培训!我培训完后再过去!基友们等我!【我在这说你们也看不到wwwwww【为什么我泉州的基友比厦门的多啊卧槽!【我究竟在题解里说了些什么……
英语捉急的我把题目贴到了翻译上还是看了好几分钟才看懂是什么意思QAQ这样下去比赛的时候字典也救不了我啊。。
题目大意:给出一堆点坐标,求最近对距离的一半
思路:分治法,把点按x排序【当然你想按y排序我也不拦你2333【我有强迫症就是要先按x排序你来打我啊~,用一条中垂线x=mid把点分成左右两边分别求左右两边的最近对。但是最近对的两个点有可能都在左边或者都在右边或者一左一右,所以要分情况考虑 反正就是求min(d,d3),d=min(d1,d2),d1是左边点集的最近对,d2是右边点集的最近对,d3是距离中垂线距离小于d的点集(再按y排序一遍可以减少循环的说2333)的最近对
我语死早好难描述啊……反正贴代码就行了吧 贴完我就要打包去旅游的行李了,明天还得去买一些旅游和社会实践需要的东西然后晚上就坐飞机去成都了代码再见~一个星期后我就回来~
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct Point
{
double x;
double y;
}point[100000],temp[100000];
bool cmp(Point a,Point b)
{
if(a.x==b.x)
return a.y<b.y;
else
return a.x<b.x;
}
bool cmpy(Point a,Point b)
{
return a.y<b.y;
}
double Min(double a,double b)
{
return a>b?b:a;
}
double Dis(Point a,Point b)
{
double x=b.x-a.x,y=b.y-a.y;
return sqrt(x*x+y*y);
}
double Solve(int l,int r)
{
if(l+1==r)
return Dis(point[l],point[r]);
if(l+2==r)
return Min(Dis(point[l],point[l+1]),Min(Dis(point[l+1],point[r]),Dis(point[l],point[r])));
int i,j,count=0,mid=(l+r)/2;
double ans=Min(Solve(l,mid),Solve(mid+1,r));
for(i=mid;i>=l && point[mid].x-point[i].x<ans;i--)
temp[count++]=point[i];
for(i=mid+1;i<=r && point[i].x-point[mid+1].x<ans;i++)
temp[count++]=point[i];
sort(temp,temp+count,cmpy);
for(i=0;i<count;i++)
{
for(j=i+1;j<count && temp[j].y-temp[i].y<ans;j++)
{
ans=Min(ans,Dis(temp[i],temp[j]));
}
}
return ans;
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF && n)
{
for(i=0;i<n;i++)
scanf("%lf%lf",&point[i].x,&point[i].y);
sort(point,point+n,cmp);
printf("%.2lf\n",Solve(0,n-1)/2);
}
return 0;
}
我终于更新博客了yyn有没有感动得泪流满面2333