ACM-计算几何之Quoit Design——hdu1007 zoj2107
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28539 Accepted Submission(s): 7469
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
pid=1007">hdu 1007
。 zoj 2107/**************************************
***************************************
* Author:Tree *
*From :http://blog.csdn.net/lttree *
* Title : Quoit Design *
*Source: hdu 1007 zoj 2107 *
* Hint : 计算几何——近期点对 *
***************************************
**************************************/
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define N 100001
struct Point
{
double x,y;
}p[N];
int arr[N];
double Min(double a,double b)
{
return a<b?a:b;
}
// 求两点之间的距离
double dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
// 依据点横坐标or纵坐标排序
bool cmp_y( int a,int b)
{
return p[a].y<p[b].y;
}
bool cmp_x( Point a,Point b)
{
return a.x<b.x;
}
// 求近期点对
double close_pair( int l,int r )
{
// 推断两个点和三个点的情况
if( r==l+1 ) return dis( p[l],p[r] );
else if( r==l+2 ) return Min( dis(p[l],p[r]),Min( dis(p[l],p[l+1]),dis(p[l+1],p[r]) ) ); int mid=(l+r)>>1;
double ans=Min(close_pair(l,mid),close_pair(mid+1,r)); int i,j,cnt=0;
// 假设 当前p[i]点 横坐标位于 范围(中点横坐标-ans,中点横坐标+ans)位置内,则记录点的序号
for(i=l; i<=r; ++i)
if( p[i].x>=p[mid].x-ans && p[i].x<=p[mid].x+ans )
arr[cnt++]=i;
// 依照纵坐标由小到大 对于arr数组内点进行排序
sort(arr,arr+cnt,cmp_y);
for(i=0; i<cnt; i++)
for(j=i+1; j<cnt; j++)
{
if(p[arr[j]].y-p[arr[i]].y>=ans) break;
ans=Min(ans,dis(p[arr[i]],p[arr[j]]));
} return ans;
} int main()
{
int i,n;
while( scanf("%d",&n)!=EOF && n)
{
for(i=0;i<n;++i)
scanf("%lf%lf",&p[i].x,&p[i].y);
// 先将全部点依照横坐标由小到大排序
sort(p,p+n,cmp_x);
printf("%.2lf\n",close_pair(0,n-1)/2.0);
}
return 0;
}
ACM-计算几何之Quoit Design——hdu1007 zoj2107的更多相关文章
- Quoit Design(hdu1007)最近点对问题。模版哦!
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU1007 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 ...
- HDU1007 Quoit Design掷环游戏
Quoit Design 看懂题意以后发现就是找平面最近点对间距离除以2. 平面上最近点对是经典的分治,我的解析 直接上代码 #include<bits/stdc++.h> using n ...
- Quoit Design(hdu1007)
---恢复内容开始--- Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- Quoit Design(最近点对+分治)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- 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) To ...
随机推荐
- o(n)解决问题:调整数组顺序是奇数位于偶数的前面
问题描述: 输入一个整数数组,调整数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分 void reOrder(int *a,int len) { if(a==NULL || ...
- sql server 实现sleep延时
sql server中实现与C++ 中Sleep类似的功能,可以使用 waitfor delay '00:00:00:10' 表示延时10毫秒
- python之数据库操作(sqlite)
python之数据库操作(sqlite) 不像常见的客户端/服务器结构范例,SQLite引擎不是个程序与之通信的独立进程,而是连接到程序中成为它的一个主要部分.所以主要的通信协议是在编程语言内的直接A ...
- 网页WEB打印控件
网页WEB打印控件制作 在WEB系统中,打印的确是比较烦人的问题,如果我们能制作一个属于自己的自定义的打印插件,那么我们在后续自定义打印的时候能随心所欲的控制打印,这样的效果对于程序员来说是非常开心的 ...
- 基于Spring的Web缓存
缓存的基本思想其实是以空间换时间.我们知道,IO的读写速度相对内存来说是非常比较慢的,通常一个web应用的瓶颈就出现在磁盘IO的读写上.那么,如果我们在内存中建立一个存储区,将数据缓存起来,当浏览器端 ...
- 基于visual Studio2013解决面试题之0604O(1)时间复杂度删除链表节点
题目
- 解决cocoapods在64位iOS7系统以下的警告问题
今天碰到一个非常奇怪的问题.XCODE提示这种警告 Pods was rejected as an implicit dependency for 'libPods.a' because its ar ...
- MySQL数据库触发器(trigger)
MySQL触发器(trigger):监视某种情况并触发某种操作 一:四要素 触发时间:before/after 地点:table 监视操作:insert/update/delete 触发操作:inse ...
- 由于“Table(T_Test)”没有主键,因此无法在其上执行 Create、Update 或 Delete 操作
在使用Linq To Sql查询的时候,遇到这么个问题,如图所示: 出现这个问题的原因就像途中所说的——没有主键(现在终于初步知道“为什么别人常说数据库中的逻辑主键是为了在编程中方便使用”的原因了,估 ...
- perl 贪婪匹配小例子
redis01:/root# cat x2.pl my $str="a19823a456123"; if ($str =~/a(.*)23/){print "1----& ...