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 ...
随机推荐
- Ultra Office Control 2.0
http://www.ultrashareware.com/Ultra-Office-Control.htm
- response.sendRedirect("")和request.getRequestDispatcher("").forward(req,resp);
1:request.getRequestDispatcher("转发路径").forward(req,resp)该语句是实现请求转发的,当请求进入到该servlet中执行到该语句时 ...
- Hadoop SequenceFile
SequenceFile格式: 每一个SequenceFile都包含一个“头”(header).Header包含了以下几部分. 1.SEQ三个字母的byte数组 2.Version number的by ...
- 【linux】内核+文件系统下载到开发板
K开发 欢迎转载,转载时请保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:htt ...
- 14.10.4 Defragmenting a Table 整理表
14.10.4 Defragmenting a Table 整理表: 随机插入或者删除从一个secondary index 可以导致index变的fragmented Fragmentation意味着 ...
- 14.10.1 InnoDB Disk I/O
14.10 InnoDB Disk IO and File Space Management InnoDB 磁盘IO和文件空间管理: 14.10.1 InnoDB Disk I/O 14.10.2 F ...
- javascript面向对象基础讲解(工厂模式、构造函数模式、原型模式、混合模式、动态原型模式)
面向对象可以把程序中的关键模块都视为对象,而模块拥有属性及方法.这样我们如果把一些属性及方法封装起来,日后使用将非常方便,也可以避免繁琐重复的工作.接下来将为大家讲解在JS中面向对象的实现. 工厂 ...
- JavaScript编程:使用DOM操作样式表
6.使用DOM操作样式表: 操纵元素的Style样式属性: background-color:style.backgroundColor color:style.col ...
- 6月19日 NSFileHandle文件类的常用方法
NSFileManager类主要对文件的操作(删除,修改,移动,复制等): NSFileHandle类主要对文件内容进行读取和写入操作 NSFileHandle处理文件的步骤 ...
- Sublime Text3 + Golang搭建开发环境
Sublime Text3 + Golang搭建开发环境 http://blog.csdn.net/aqiang912/article/details/46775409 1.安装git 因为golan ...