博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1007 Quoit Design竟然要分治
阅读量:5243 次
发布时间:2019-06-14

本文共 3288 字,大约阅读时间需要 10 分钟。

Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 34742    Accepted Submission(s): 9066

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
 

 

Author
CHEN, Yue
 

 

Source
 

 

Recommend
JGShining   |   We have carefully selected several similar problems for you:            
 
说实话,这道题真的很让我崩溃,刚开始看题目的时候觉得只要把各个点记录下来,然后按照横坐标和纵坐标来排序就好了,但是提交之后是WA,然后考虑了很久,觉得这样排序并没有什么不妥,但是突然发现其实这离答案还差的远,因为如果是A、B、C三个已经按照横坐标顺序排好序的点,如果AB的纵坐标相差非常之大,那么还是可能和C点的距离比较近。后来翻阅到编程之美中的文章有关介绍最近点对的问题的,给出了一维情况下的代码,二维情况时有思维讲解,即用分治的思路去考虑。
然而这里还有一点要进行证明以完成剪枝。即两点间的横坐标之间的距离差一定是小于等于它们之间直接的距离之差的,所以每次在进行区间的判断的时候可以只是先按照这个计算量小的方式进行判断,最后在那个不能再细分的区间里按照纵坐标再间接排序一次,然后暴力求解。
代码君:
#include
#include
#include
#define maxn 1100010#define INF 214748364using namespace std;int q[maxn];struct Point{ double x,y;};bool cmp_x(Point a,Point b){ return a.x < b.x;}Point arry[maxn];bool cmp_y(int a,int b){ return arry[a].y < arry[b].y;}double calc(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));}double Divide_conquer(int l,int r){ if(l >= r) return INF; int n = 0; int m = (l+r)>>1; double a = min(Divide_conquer(l,m),Divide_conquer(m+1,r)); for(int i = m;i >= l;--i){ if(arry[m].x - arry[i].x < a) q[n++] = i; else break; } for(int i = m+1;i <= r;++i){ if(arry[i].x - arry[m].x < a) q[n++] = i; else break; } sort(q, q+n, cmp_y); for(int i = 0;i < n;i++){ for(int j = i+1;j < n;j++){ if(arry[q[j]].y - arry[q[i]].y < a) a = min(a,calc(arry[q[i]],arry[q[j]])); else break; } } return a;}int main(){ int n; while(~scanf("%d",&n) && n){ for(int i = 0;i < n;i++){ scanf("%lf%lf",&arry[i].x,&arry[i].y); } sort(arry,arry+n,cmp_x); printf("%.2f\n",Divide_conquer(0,n-1)/2); } return 0;}

 

转载于:https://www.cnblogs.com/lccurious/p/5079880.html

你可能感兴趣的文章
光脚丫学LINQ(042):如何将列表示为由数据库生成的列
查看>>
[转]在 .NET 中远程请求 https 内容时,发生错误:根据验证过程,远程证书无效...
查看>>
编程之美a题小数据 学习用sstream 处理字符串
查看>>
助教小结6
查看>>
微信开发
查看>>
ContentProvider 增删改查通讯录
查看>>
SeleniumIDE与eclipse如何连接使用
查看>>
vue实战(8):完整开发登录页面(二)
查看>>
iOS导航栏的正确隐藏方式
查看>>
rabbitmq 安装和配置
查看>>
【分享】跟刘皇叔学习寻找执行力人才
查看>>
解决.NET WebService引用后添加HTTP Header的问题
查看>>
Apk去掉签名以及重新签名的方法
查看>>
Spark大数据平台安装教程
查看>>
Python--并发编程之IO模型
查看>>
Rsync参数介绍
查看>>
【BZOJ-2055】80人环游世界 上下界费用流 (无源无汇最小费用流)
查看>>
property,类和类之间的关系
查看>>
CSS选择器(中)——高级选择器
查看>>
Tail Recursion, Recursion, Concepts and Examples
查看>>