poj 1007 Quoit Design(分治)
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29694 Accepted Submission(s): 7788
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.
by N = 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
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std; const double eps = 1e-7;
const double INF = 100000000000;
struct point{
double x , y;
point(double a = 0 , double b = 0){
x = a , y = b;
}
};
vector<point> P;
int N; bool cmp(point p1 , point p2){
if(p1.x == p2.x) return p1.y<p2.y;
return p1.x<p2.x;
} bool cmpy(point p1 , point p2){
return p1.y<p2.y;
} void initial(){
P.clear();
} void readcase(){
double x , y;
for(int i = 0; i < N; i++){
scanf("%lf%lf" , &x , &y);
P.push_back(point(x , y));
}
} double dis(point p1 , point p2){
return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
} double fenzhi(int l , int r){
if(l == r) return INF;
if(r-l==1) return dis(P[l] , P[r]);
int mid = (l+r)/2;
double d = min(fenzhi(l,mid) , fenzhi(mid+1 , r));
int index = mid;
vector<point> tP;
for(int i = mid+1; i <= r; i++){
if(d-(P[i].x-P[mid].x) >= eps) tP.push_back(P[i]);
}
sort(tP.begin() , tP.end() , cmpy);
while(d-(P[mid].x-P[index].x) >= eps && index >= l){
for(int i = 0; i < tP.size(); i++){
if(tP[i].y-P[index].y-d>=eps) break;
d = min(d , dis(tP[i] , P[index]));
}
index--;
}
return d;
} void computing(){
sort(P.begin() , P.end() , cmp);
printf("%.2lf\n" , fenzhi(0 , N-1)/2);
} int main(){
while(scanf("%d" , &N) && N){
initial();
readcase();
computing();
}
return 0;
}
poj 1007 Quoit Design(分治)的更多相关文章
- 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 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) To ...
- hdu 1007 Quoit Design (最近点对问题)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 杭电OJ——1007 Quoit Design(最近点对问题)
Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...
- 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design
题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...
- hdu 1007 Quoit Design(分治)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:给出n个点求最短的两点间距离除以2. 题解:简单的分治. 其实分治就和二分很像二分的写df ...
- hdu 1007 Quoit Design (经典分治 求最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
随机推荐
- idea 设置svn忽略 .idea内的文件
从ToolView中打开 Version Control -> Local Changes 中的Default ChangesList里面的文件全选中右键选择 Move to Anothe ...
- 成为IT经理必备的十大能力 不只是技术!
对于一个IT从业者,让你谋得工作的也许是技术能力,但有助于提升职业生涯的却是软技能.步步高升的人都是那些发表文章.在会议上积极发言以及关注客户的员工(程序员).与此同时,通常情况下,企业CIO或多或少 ...
- ubuntu 安装 theano
参考博客: http://www.cnblogs.com/anyview/p/5025704.html 1. 安装gfortran, numpy, scipy, sklearn, blas, atla ...
- String 的常用操作
String 类,我可以不负责的说在 Java 中这个类应该是使用最频繁的类了.然而关于它的常用的操作,我却不甚了解.整理这个东西很反人性的,这些方法,你看到他的时候感觉很简单,但是真正用的时候还是不 ...
- Android自动化页面测速在美团的实践
背景 随着移动互联网的快速发展,移动应用越来越注重用户体验.美团技术团队在开发过程中也非常注重提升移动应用的整体质量,其中很重要的一项内容就是页面的加载速度.如果发生冷启动时间过长.页面渲染时间过长. ...
- <泛> 归并排序 及 逆序对
今天写一个归并排序的模板,返回值为该序列的逆序对数 基本思路 归并排序就是利用二分的思想,将区间无限递归二分,直到当前划分区间只包含一个元素或没有元素的时候(我们认为这个序列是自动有序的),我们回溯到 ...
- bzoj 4408: [Fjoi 2016]神秘数 数学 可持久化线段树 主席树
https://www.lydsy.com/JudgeOnline/problem.php?id=4299 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1 ...
- 6.13校内互测 (DP 带权二分 斜率优化)
丘中有麻plant 改自这儿,by ZBQ. 还有隐藏的一页不放了.. 直接走下去的话,如果开始时间确定那么到每个点的时间确定,把time减去dis就可以去掉路程的影响了. 这样对于减去d后的t,如果 ...
- BZOJ 3751: [NOIP2014]解方程 数学
3751: [NOIP2014]解方程 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3751 Description 已知多项式方程: ...
- BZOJ 1007: [HNOI2008]水平可见直线 栈/计算几何
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MB 题目连接 http://www.lydsy.com/JudgeOnline ...