HDOJ1007 Quoit Design

来源:互联网 发布:现货模拟交易软件下载 编辑:程序博客网 时间:2024/05/16 09:38

Quoit Design

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


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
20 01 121 11 13-1.5 00 00 1.50
 

Sample Output
0.710.000.75
 
题目其实就是求2点最近的距离的二分之一。
//按照每个点 x 值由小到大进行排序,若 x 相同,则按照 y 由小到大进行排序,计算相邻两点的最短距离,即为len1。//按照每个点 y 值由小到大进行排序,若 y 相同,则按照 x 由小到大进行排序,计算相邻两点的最短距离,即为len2。


#include<stdio.h>#include<math.h>#include<algorithm>using namespace std;typedef struct point{double x;double y;}point;point coor[100001];bool cmp1(const point a,const point b){if(a.x<b.x)return true;if(a.x>b.x)return false;elsereturn a.y<b.y;}bool cmp2(const point a,const point b){if(a.y<b.y)return true;if(a.y>b.y)return false;elsereturn a.x<b.x;}double juli(int i,int j){return sqrt( pow( (coor[i].x-coor[j].x),2 ) + pow( (coor[i].y-coor[j].y),2 ) ); }int main(){int N;double rad=0;while(scanf("%d",&N)&&N!=0){for(int i=0;i<N;i++){scanf("%lf %lf",&coor[i].x,&coor[i].y);}sort(coor,coor+N,cmp1);rad=juli(0,1);//初始化半径 for(int i=1;i<N-1;i++) { if(rad>juli(i,i+1)) rad=juli(i,i+1); } sort(coor,coor+N,cmp2); for(int i=1;i<N-1;i++) { if(rad>juli(i,i+1)) rad=juli(i,i+1); } printf("%.2f\n",rad/2);}return 0;}


0 0
原创粉丝点击