Quoit Design(hdu1007)最近点对问题。模版哦!
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30919 Accepted Submission(s):
8120
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.
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.
ring required by the Cyberground manager, accurate up to 2 decimal places.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define Max(x,y) (x)>(y)?(x):(y)
struct Q
{
double x, y;
} q[], sl[], sr[]; int cntl, cntr, lm, rm; double ans;
int cmp(const void*p1, const void*p2)
{
struct Q*a1=(struct Q*)p1;
struct Q*a2=(struct Q*)p2;
if (a1->x<a2->x)return -;
else if (a1->x==a2->x)return ;
else return ;
}
double CalDis(double x1, double y1, double x2, double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
void MinDis(int l, int r)
{
if (l==r) return;
double dis;
if (l+==r)
{
dis=CalDis(q[l].x,q[l].y,q[r].x,q[r].y);
if (ans>dis) ans=dis;
return;
}
int mid=(l+r)>>, i, j;
MinDis(l,mid);
MinDis(mid+,r);
lm=mid+-;
if (lm<l) lm=l;
rm=mid+;
if (rm>r) rm=r;
cntl=cntr=;
for (i=mid; i>=lm; i--)
{
if (q[mid+].x-q[i].x>=ans)break;
sl[++cntl]=q[i];
}
for (i=mid+; i<=rm; i++)
{
if (q[i].x-q[mid].x>=ans)break; sr[++cntr]=q[i];
}
for (i=; i<=cntl; i++)
for (j=; j<=cntr; j++)
{
dis=CalDis(sl[i].x,sl[i].y,sr[j].x,sr[j].y);
if (dis<ans) ans=dis;
}
}
int main()
{
int n, i;
while (scanf("%d",&n)==&&n)
{
for (i=; i<=n; i++)
scanf("%lf%lf", &q[i].x,&q[i].y);
qsort(q+,n,sizeof(struct Q),cmp);
ans=CalDis(q[].x,q[].y,q[].x,q[].y);
MinDis(,n);
printf("%.2lf\n",ans/2.0);
}
return ;
}
Quoit Design(hdu1007)最近点对问题。模版哦!的更多相关文章
- Quoit Design(最近点对+分治)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- ACM-计算几何之Quoit Design——hdu1007 zoj2107
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU-1007 Quoit Design 平面最近点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...
- HDOJ-1007 Quoit Design(最近点对问题)
http://acm.hdu.edu.cn/showproblem.php?pid=1007 给出n个玩具(抽象为点)的坐标 求套圈的半径 要求最多只能套到一个玩具 实际就是要求最近的两个坐标的距离 ...
- 【HDOJ】P1007 Quoit Design (最近点对)
题目意思很简单,意思就是求一个图上最近点对. 具体思想就是二分法,这里就不做介绍,相信大家都会明白的,在这里我说明一下如何进行拼合. 具体证明一下为什么只需要检查6个点 首先,假设当前左侧和右侧的最小 ...
- 杭电OJ——1007 Quoit Design(最近点对问题)
Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...
- ZOJ 2017 Quoit Design 经典分治!!! 最近点对问题
Quoit Design Time Limit: 5 Seconds Memory Limit: 32768 KB Have you ever played quoit in a playg ...
- 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 ...
随机推荐
- .net图表之ECharts随笔06-这才是最简单的
今天搞柱形图的时候,发现了一个更简单的用法.那就是直接使用带all的那个js文件 基本步骤: 1.为ECharts准备一个具备大小(宽高)的Dom 2.ECharts的js文件引入(echarts-a ...
- DDD Code First 迁移数据实现EF CORE的软删除,值对象迁移配置
感谢Jeffcky大佬的博客: EntityFramework Core 2.0全局过滤 (HasQueryFilter) https://www.cnblogs.com/CreateMyself/p ...
- 文件上传下载、socketserver(并发)、解读socketserver源码
1.文件上传/下载 学习了socket套接字,我们现在可以写一个文件上传/下载的程序,如下示例: 分析上边代码,我们发现,client发送上传文件相关信息的字典序列化之后,server又给client ...
- Akka(0):聊聊对Akka的初步了解和想法
前一段时间一直沉浸在函数式编程模式里,主要目的之一是掌握一套安全可靠的并发程序编程方法(concurrent programming),最终通过开源项目FunDA实现了单机多核CPU上程序的并行运算. ...
- [Visual Studio] 记一次排错:打不开 Nuget 包管理器里的安装package页面,无法 安装 / 恢复 包
出差一阵子PC很久没用了, 回来在用Visual Studio (2017) 的时候, 工程里无法安装Package了 >_< --- 也不知道电脑做了什么?--- Nuget包管 ...
- centos 安装oracle 11g r2(三)-----表空间创建
centos 安装oracle 11g r2(三)-----表空间创建 创建表空间前要保证监听与数据库实例已经启动 1.启动监听 [oracle@localhost ~]$ lsnrctl start ...
- linux源码安装的步骤
源码安装的过程中多多少少会遇到问题,在此仅简述一下安装的步骤,具体安装的过程中遇到的问题,具体解决. 安装步骤: 1.获取源码 name.gz 2.解包 tar -xvf name.gz (cd到包解 ...
- 优化openfire服务器提升xmpp 效率的15个方法(原创)
1.禁用原生xmpp搜索,使组织架构.人员数据本地化保存,并使客户端数据同步服务器,降低原生xmpp搜索的iq消耗,因为搜索是im应用的频繁操作: 2.禁用roster花名册.禁用presence包通 ...
- Mybatis 逆向工程学习随笔
一.逆向工程的作用 简单来说,就是替我们生成Java代码. 之前使用Mybatis的Mapper代理方法开发,还需要自己创建实体类,而且属性还得和数据库中的字段对应.这着实是机械化的而且比较麻烦的事, ...
- [0day]微软VS全版本DLL却持漏洞(VS2015 VS2013 VS2012 VS2010 VS2008)
<无敌破坏王>大师兄说的 "我不是针对谁,而是在座的各位,都是垃圾"前几天在国外论坛看到一个VS2010 DLL却持漏洞 测试发现是全版本 实际上2014年在某越南黑客 ...