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.
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
- HDOJ1007 Quoit Design
- hdoj1007(最近距离点对)Quoit Design
- Quoit Design
- Quoit Design
- Quoit Design
- Quoit Design
- quoit Design
- hdoj1007
- hdoj1007
- hdoj1007
- HDU1007 Quoit Design
- 1007:Quoit Design
- HDOJ 1007 Quoit Design
- hdu 1007 Quoit Design
- zoj 2107 Quoit Design
- hdu 1007 Quoit Design
- hdu 1007 Quoit Design
- HDU-1007 Quoit Design
- sql server游标使用示例
- MySQL Workbench “Error Code: 1175” 的解决方法
- 导入项目jdk不匹配的问题
- 面向对象设计原则 面向对象设计原则概述
- VSAN底层架构细节
- HDOJ1007 Quoit Design
- 【图形学与游戏编程】开发笔记-基础篇7:纹理映射
- 二叉堆的实现C语言
- java.lang.UnsatisfiedLinkError: Couldn't load dnlocal from loader dalvik.system.PathClassLoader
- 技术英文单词记忆-react
- iOS RunLoop 初识
- 面向对象设计原则 面向对象设计原则之单一职责原则
- wapmserver设置数据库密码
- 深度学习——缩减+召回加速网络训练