题目内容:

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

题目大意:

对于给定的点,找到距离最近的两个点的距离,并且把它的一半作为输出结果,即题目所说的环的最小半径

题目分析:

这道题的关键是在于数学方面,可以证得最近的两个点一定是横坐标上的相邻点或者纵坐标上的最近点,然后再代入相应的另一个数据,进行求算即可,注意对于时间复杂度的优化

题目代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>using namespace std;typedef struct
{double xi;double yi;
}data;int n;
data xsort[100005];
data ysort[100005];int cmpx(data a,data b)
{if(a.xi<b.xi)return 1;else if(a.xi>b.xi)return 0;else{if(a.yi<b.yi)return 1;elsereturn 0;}
}int cmpy(data a,data b)
{if(a.yi<b.yi)return 1;else if(a.yi>b.yi)return 0;else{if(a.xi<b.xi)return 1;elsereturn 0;}
}double mins(double a,double b)
{return a<b?a:b;
}double dd(double a)
{return a*a;
}int main()
{while(scanf("%d",&n),n!=0){memset(xsort,0,sizeof(xsort));memset(ysort,0,sizeof(ysort));double min=999999;for(int i=0;i<n;i++){scanf("%lf%lf",&xsort[i].xi,&xsort[i].yi);ysort[i].xi=xsort[i].xi,ysort[i].yi=xsort[i].yi;}sort(xsort,xsort+n,cmpx);sort(ysort,ysort+n,cmpy);min=dd(xsort[0].xi-xsort[1].xi)+dd(xsort[0].yi-xsort[1].yi);for(int i=1;i<n-1;i++){min=mins(min,dd(xsort[i].xi-xsort[i-1].xi)+dd(xsort[i].yi-xsort[i-1].yi));min=mins(min,dd(xsort[i].xi-xsort[i+1].xi)+dd(xsort[i].yi-xsort[i+1].yi));}min=mins(min,dd(xsort[n-1].xi-xsort[n-2].xi)+dd(xsort[n-1].yi-xsort[n-2].yi));min=mins(min,dd(ysort[0].xi-ysort[1].xi)+dd(ysort[0].yi-ysort[1].yi));for(int i=1;i<n-1;i++){min=mins(min,dd(ysort[i].xi-ysort[i-1].xi)+dd(ysort[i].yi-ysort[i-1].yi));min=mins(min,dd(ysort[i].xi-ysort[i+1].xi)+dd(ysort[i].yi-ysort[i+1].yi));}min=mins(min,dd(ysort[n-1].xi-ysort[n-2].xi)+dd(ysort[n-1].yi-ysort[n-2].yi));printf("%.2lf\n",(double)sqrt(min)/2);}return 0;
}

解题评价:

看到discuss区很多人都说这是一个分治法的经典题目,其实我在题目中也运用了分治的思想,不过我仍然认为这道题的最主要是在于数学思想和时间优化

当前水平评分:4

杭电1007 Quoit Design相关推荐

  1. HDU.1007 Quoit Design

    文章目录 一.题目解读 1.原题 2.分类 3.题意 4.输入输出格式 5.数据范围 二.题解参考 1.总体思路 2.思路② (1).分析 (2).AC代码 三.总结与后话 1.评价 2.后话 一.题 ...

  2. HDU 1007 Quoit Design(分治)

    Description   给出n个点的坐标,输出点集中距离最近两点间距离的一半  Input   多组输入,每组用例第一行为点数n,之后n行每行两个浮点数表示一个点的横纵坐标,以n=0结束输入  O ...

  3. 杭电OJ分类题目(1)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...

  4. hdoj杭电问题分类

    杭电上的题虽然多,但是一直苦于找不到问题分类,网页都是英文的,所以平时做题也没怎么看,今天仔细一看,问题分类竟然就在主页....做了那么久的题居然没发现,表示已经狗带..不要笑,不知道有没有像我一样傻 ...

  5. 杭电1108java_按照这个步骤来刷题,迷茫的你两个月亦能成为王者

    原标题:按照这个步骤来刷题,迷茫的你两个月亦能成为王者 作者 | bigsai 来源 | bigsai(ID:bigsai) 前言 大家好,我是bigsai哥哥.最近很多小伙伴问我怎么入门数据结构与算 ...

  6. 杭电OJ分类题目(2)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(2) HDU Water~~~ HDU 100 ...

  7. 杭电 2016 计算机组成原理,杭电计算机组成原理多功能ALU设计实验

    <杭电计算机组成原理多功能ALU设计实验>由会员分享,可在线阅读,更多相关<杭电计算机组成原理多功能ALU设计实验(6页珍藏版)>请在人人文库网上搜索. 1.杭州电子科技大学计 ...

  8. 杭电oj题目题型分类(转)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  9. 2015年杭电计算机存储器扩展,杭电计算机组成原理存储器设计实验5

    <杭电计算机组成原理存储器设计实验5>由会员分享,可在线阅读,更多相关<杭电计算机组成原理存储器设计实验5(4页珍藏版)>请在人人文库网上搜索. 1.杭州电子科技大学计算机学院 ...

最新文章

  1. CentOS 6.5下Redis安装配置记录
  2. AD5933不同频率下的转换结果
  3. Linux 操作系统原理 — 内存 — 基于局部性原理实现的内/外存交换技术
  4. 机器人学的几何基础pdf
  5. Linux与jvm内存关系分析
  6. 算法之排序算法-直接插入排序
  7. Serverless 服务选型
  8. notepad++ 偶数行_C ++程序查找前N个偶数的立方和
  9. 基于TMS320VC5507的语音识别系统实现
  10. Eclipse中修改SVN地址
  11. markdown一边写一边预览_MarkDown使用笔记
  12. 理解去中心化稳定币DAI
  13. Jmeter的脚本录制(App)
  14. 什么是系统漏洞,如何处理?
  15. MyExcel 2.1.2 版本发布,重要 Bug 修复
  16. 来!带你认识几种最流行的Python编辑器/IDEs
  17. 顶!Python 与 Excel 终于在一起了
  18. 蓝桥杯 动态数码管中的延时处理
  19. Mendix敏捷开发零基础学习《三》-高级 (数据删除保护机制、数据关联删除、Security安全、调用外部接口、调用JAVA代码)
  20. 机械革命s1 pro ubunntu18.04 双系统 并配置nvidia驱动

热门文章

  1. 12306的架构部署
  2. 关于背单词的一点个人体会 (好文章)
  3. Java设计模式19:观察者模式(Observer)
  4. 用C++写出求矩形和圆形面积的程序
  5. 自定义函数求圆和圆柱体的表面积
  6. 你应该解雇工作狂程序员的5个原因
  7. 2019年最新《Web 前端开发》等级考试模拟题~以国家 “1+X” 职业技能证书为标准,厚溥推出 Web 前端开发人才培养方案...
  8. WIM文件怎么安装系统Win10
  9. 作业1开发一个简单的python计算器
  10. JavaScript学习第二部-js的基础语法和语句