Quoit Design

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30919 Accepted Submission(s):
8120

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
 
 
题意:找任意两点之间距离最短的输出!!!
方法:模版题,最近点对问题。                            我又多了份模版。
#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)最近点对问题。模版哦!的更多相关文章

  1. Quoit Design(最近点对+分治)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

  2. ACM-计算几何之Quoit Design——hdu1007 zoj2107

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. HDU-1007 Quoit Design 平面最近点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...

  4. HDOJ-1007 Quoit Design(最近点对问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 给出n个玩具(抽象为点)的坐标 求套圈的半径 要求最多只能套到一个玩具 实际就是要求最近的两个坐标的距离 ...

  5. 【HDOJ】P1007 Quoit Design (最近点对)

    题目意思很简单,意思就是求一个图上最近点对. 具体思想就是二分法,这里就不做介绍,相信大家都会明白的,在这里我说明一下如何进行拼合. 具体证明一下为什么只需要检查6个点 首先,假设当前左侧和右侧的最小 ...

  6. 杭电OJ——1007 Quoit Design(最近点对问题)

    Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...

  7. ZOJ 2017 Quoit Design 经典分治!!! 最近点对问题

    Quoit Design Time Limit: 5 Seconds      Memory Limit: 32768 KB Have you ever played quoit in a playg ...

  8. HDU 1007 Quoit Design(经典最近点对问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

  9. hdu 1007 Quoit Design (最近点对问题)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. VS2015ASP.NET MVC5项目中Spring.NET配置方法(超详细)

    首先,在ASP.NET MVC5项目右键,如下图所示,选择“管理Nuget程序包...” 然后,在弹出的页面的搜索框中输入“spring.web”,在返回结果中选择Spring.Web和Spring. ...

  2. Mongodb-- python中使用pymongo连接mongodb数据库

    一.使用 通过pip或者pychrm下载pymongo模块 import json from pymongo import MongoClient from bson import ObjectId ...

  3. TCPDUMP学习笔记。

    1.启动 普通情况下,直接启动tcpdump将监视第一个网络界面上所有流过的数据包,注意这里使用超级用户.当用户上网得时候,就会将监视得数据打印出来. 我没使用root用户,结果输入tcpdump命令 ...

  4. centos docker 安装笔记

    安装epel rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm --import ...

  5. 【sping揭秘】10、SpringIOC容器扩展

    关于component-scan操作(去除,失效) 这个spring中的配置项,可以扫描我们对应的包下面的类,自动把带上@component,@service,@controller, @reposi ...

  6. 解决白屏(vue) - webpace es6转es5

    1.npm安装 npm install babel-polyfillnpm install es6-promise package.json中会出现 "babel-polyfill" ...

  7. [转]网页实时聊天之js和jQuery实现ajax长轮询 PHP

    网页实时聊天之js和jQuery实现ajax长轮询 众所周知,HTTP协议是无状态的,所以一次的请求都是一个单独的事件,和前后都没有联系.所以我们在解决网页实时聊天时就遇到一个问题,如何保证与服务器的 ...

  8. unittest单元测试框架简单说明

    unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...

  9. WTF小程序之<web-view>

    叨叨两句 昨天爬了一下午坑才出来的我向大家问好

  10. Activity四大启动模式

    ctivity的四种启动模式: standard.singleTop.singleTask.singleInstance 为了打印方便,定义一个基础Activity,在其onCreate方法和onNe ...