HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 47104 Accepted Submission(s): 12318
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.
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
0.00
0.75
题目链接:HDU 1007
题目本身有很简单的做法就是排个序找到最小的nearst_r输出即可,但是如果用二分来做的话就很容易WA,浮点数二分跟整数二分还是有点不同的,第一次运气好把eps定为1e-3居然也过了……后来了解了一下浮点数的二分其实没这么简单,精度一般要控制在1e-5,如果题目要求更高那eps就要更小,还有L与R就不需要再加减了,直接等于mid就可以,条件也要改为R-L>eps……
代码:
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=100010;
struct info
{
double x,y;
bool operator<(const info &b)const
{
if(y==b.y)
return x<b.x;
return y<b.y;
}
double nearst_r;
};
info pos[N];
int n;
inline double getdx(const info &a,const info &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
inline bool check(const double &r)
{
for (int i=1; i<n; ++i)
if(r>pos[i].nearst_r)
return false;
return true;
}
int main(void)
{
int i,j;
double L,R,ans,mid,eps=1e-5;
while (~scanf("%d",&n)&&n)
{
for (i=0; i<n; ++i)
scanf("%lf%lf",&pos[i].x,&pos[i].y);
sort(pos,pos+n);
for (i=1; i<n; ++i)
pos[i].nearst_r=getdx(pos[i],pos[i-1])/2.0;
L=0,R=1e9;
while (R-L>=eps)
{
mid=(L+R)/2.0;
if(check(mid))
L=mid;
else
R=mid;
}
printf("%.2lf\n",mid);
}
return 0;
}
HDU 1007 Quoit Design(二分+浮点数精度控制)的更多相关文章
- HDU 1007 Quoit Design(经典最近点对问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- hdu 1007 Quoit Design 分治求最近点对
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1007 Quoit Design (最近点对问题)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1007 Quoit Design【计算几何/分治/最近点对】
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1007 Quoit Design(分治)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:给出n个点求最短的两点间距离除以2. 题解:简单的分治. 其实分治就和二分很像二分的写df ...
- HDU 1007 Quoit Design 平面内最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...
- hdu 1007 Quoit Design (经典分治 求最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
- HDU 1007 Quoit Design
传送门 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Des ...
- HDU 1007 Quoit Design(计算几何の最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
随机推荐
- poj 1007 DNA Sorting 解题报告
题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...
- 侃侃前端MVC设计模式
前言 前端的MVC,近几年一直很火,大家也都纷纷讨论着,于是乎,抽空总结一下这个知识点.看了些文章,结合实践略作总结并发表一下自己的看法. 最初接触MVC是后端Java的MVC架构,用一张图来表示之— ...
- SVN常见错误和版本冲突解决
之前在Eclipse下面误删除了svn的一些插件包,后来重装了就问题重重,在这里还是建议, Windows下SVN最好使用桌面版,在文件管理器下面更新和提交. 1.常见错误整理 #, c-format ...
- poj 1753
翻转棋,注意是翻转周围四个的,不是整行列的 汗-_-! 哥的代码风还是不错的 二进制储存状态 Sample Input bwwb bbwb bwwb bwww Sample Output 4 #in ...
- 【GruntMate】一个让你更方便使用Grunt的工具
GruntMate是什么? 一个基于Grunt的项目管理可视化工具(还不知道Grunt是什么?可以谷歌一下就知道了!) GruntMate有哪些功能? 方便的管理基于Grunt的项目 方便统一管理Gr ...
- Android快捷开关实现(转)
在Android源码中,提供的快捷开关相对是比较少的,Android4.0系统默认提供的桌面快捷开关AppWidget上只有5种开关(分别是Wifi开关.蓝牙开关.GPS开关.同步开关.亮度设置开关) ...
- UVALive 6884 GREAT + SWERC = PORTO dfs模拟
题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- Codeforces Round #Pi (Div. 2) A. Lineland Mail 水
A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...
- cocos2dx游戏开发——微信打飞机学习笔记(四)——GameScene的搭建
一.创建文件 首先呢,就是那个创建新的.h 和 .cpp 的文件,然后可以起名为GameScene 最重要的就是一定要创建在Classes的目录下哦= =,别手抖= =. 二.GameScene.h和 ...
- 【转】cloudera新增用户权限配置
转自 http://lookqlp.iteye.com/blog/2189119 . 配置起来较复杂,需要在有测试环境之后再进行配置测试. 之后是有上HUE的计划的,所以这个也是一定要做的. ...