Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43918 Accepted Submission(s): 11417
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.
2 0 0 1 1 2 1 1 1 1 3 -1.5 0 0 0 0 1.5 0
0.71 0.00 0.75 分析题目可知,这题就是要求任意2点之间最短的距离 ,唉,好难啊,我需要停一停咯。http://blog.163.com/jackie_howe/blog/static/199491347201232553039178/#include "stdafx.h" #include<iostream> #include<algorithm> #include<cmath> using namespace std; static const int MAXNUM=100000; struct Point { double x,y; }arrP[MAXNUM],arrX[MAXNUM],arrY[MAXNUM]; bool CompX(Point a,Point b) { if(a.x==b.x) return a.y<b.y; return a.x<b.x; } bool CompY(Point a,Point b) { if(a.y==b.y) return a.x<b.x; return a.y<b.y; } double GetDistance(Point a,Point b) { return sqrt(pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0)); } double MinDistance(double a,double b) { return a<=b ? a : b; } double GetMinDistance(int l,int r) { if(l==r) //only one point return 0; else if(l+1==r) //only two points return GetDistance(arrP[l],arrP[r]); else if(l+2==r) //only three points { double tmp1=GetDistance(arrP[l],arrP[l+1]); double tmp2=GetDistance(arrP[l],arrP[r]); double tmp3=GetDistance(arrP[l+1],arrP[r]); return MinDistance(MinDistance(tmp1,tmp2),tmp3); } //more than three points int middle=(l+r)/2,j=0,k=0; double minDistance=MinDistance(GetMinDistance(l,middle),GetMinDistance(middle+1,r)); for(int i=l;i<=r;i++) { if(fabs(arrP[i].x-arrP[middle].x)<minDistance) arrX[j++]=arrP[i]; } sort(arrX,arrX+j,CompY); middle=(j+1)/2; for(int i=0;i<j;i++) { if(fabs(arrX[i].y-arrX[middle].y)<minDistance) arrY[k++]=arrX[i]; } for(int i=0;i<k;i++) for(int j=i+1;j<k;j++) { double tmpDistance=GetDistance(arrY[i],arrY[j]); if(tmpDistance<minDistance) minDistance=tmpDistance; } return minDistance; } int main() { int n; while(cin>>n && n!=0) { Point p; double minDistance; for(int i=0;i<n;i++) { cin>>arrP[i].x>>arrP[i].y; } sort(arrP,arrP+n,CompX); minDistance=GetMinDistance(0,n-1); cout.precision(2); cout<<fixed<<minDistance/2<<endl; } return 0; }
1726




被折叠的 条评论
为什么被折叠?



