题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007

Each person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.
The world king Sconbin is not the exception.One day,Sconbin was
sleeping,then swakened by one nightmare.It turned out that his love letters to
Dufein were made public in his dream.These foolish letters might ruin his
throne.Sconbin decided to destroy the letters by the military exercises's
opportunity.The missile is the best weapon.Considered the execution of the
missile,Sconbin chose to use one missile with the minimum
destruction.
Sconbin had writen N letters to Dufein, she buried these letters
on different places.Sconbin got the places by difficult,he wants to know where
is the best place launch the missile,and the smallest radius of the burst area.
Let's help Sconbin to get the award.
题意描述:给出n封信的二维坐标,找到一个坐标点,使其距离n封信的最远距离最近。
算法分析:最远点对的模板题。需要注意一点:题目中的坐标点没规律,最远点对的算法针对凸边形,所以首先我们得对题目点集凸包化。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#define inf 0x7fffffff
#define exp 1e-10
#define PI 3.141592654
using namespace std;
const int maxn=+; int n;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){}
}an[maxn],bn[maxn];
typedef Point Vector;
double dcmp(double x)
{
if (fabs(x)<exp) return ;
return x< ? - : ;
}
Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x , A.y+B.y); }
Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x , A.y-B.y); }
Vector operator * (Vector A,double p) {return Vector(A.x*p , A.y*p); }
Vector operator / (Vector A,double p) {return Vector(A.x/p , A.y/p); }
bool operator < (Point a,Point b) {return a.x<b.x || (a.x==b.x && a.y<b.y); }
bool operator == (Point a,Point b) {return dcmp(a.x-b.x)== && dcmp(a.y-b.y)==; } double Dot(Vector A,Vector B) {return A.x*B.x + A.y*B.y ; }
double Length(Vector A,Vector B) {return sqrt(Dot(A,A)); }
double cross(Vector A,Vector B) {return A.x*B.y - B.x*A.y; } double dist(Point A,Point B)
{
double xx=(A.x-B.x)*(A.x-B.x);
double yy=(A.y-B.y)*(A.y-B.y);
return sqrt(xx+yy);
} Point cur;
double rotating_calipers(Point *ch,int n)
{
int q=;
double ans=-;
cur.x=cur.y=;
ch[n]=ch[];
for (int p= ;p<n ;p++)
{
while (cross(ch[q+]-ch[p+],ch[p]-ch[p+])>cross(ch[q]-ch[p+],ch[p]-ch[p+]))
q=(q+)%n;
double len=dist(ch[p],ch[q]);
double len2=dist(ch[p+],ch[q+]);
if (len>ans+exp)
{
ans=len;
cur.x=(ch[p].x+ch[q].x)/2.0;
cur.y=(ch[p].y+ch[q].y)/2.0;
}
if (len2>ans+exp)
{
ans=len2;
cur.x=(ch[p+].x+ch[q+].x)/2.0;
cur.y=(ch[p+].y+ch[q+].y)/2.0;
}
}
return ans;
} int Convexhull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
for (int i= ;i<n ;i++)
{
while (m> && dcmp(cross(ch[m-]-ch[m-],p[i]-ch[m-]))<) m--;
ch[m++]=p[i];
}
int k=m;
for (int i=n- ;i>= ;i--)
{
while (m>k && dcmp(cross(ch[m-]-ch[m-],p[i]-ch[m-]))<) m--;
ch[m++]=p[i];
}
if (n>) m--;
return m;
} int main()
{
while (scanf("%d",&n)!=EOF && n)
{
for (int i= ;i<n ;i++) scanf("%lf%lf",&an[i].x,&an[i].y);
if (n==) {printf("%.2lf %.2lf 0.00\n",an[].x,an[].y);continue; }
if (n==) {printf("%.2lf %.2lf %.2lf\n",(an[].x+an[].x)/2.0,
(an[].y+an[].y)/2.0,dist(an[],an[])/2.0);continue; }
int m=Convexhull(an,n,bn);
double ans=rotating_calipers(bn,m);
printf("%.2lf %.2lf %.2lf\n",cur.x,cur.y,ans/2.0);
}
return ;
}

hdu 3007 Buried memory 最远点对的更多相关文章

  1. HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)

    Problem Description Each person had do something foolish along with his or her growth.But,when he or ...

  2. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

    题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...

  3. HDU - 3007 Buried memory

    传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...

  4. 【HDOJ】3007 Buried memory

    1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示 ...

  5. HDU 3007 模拟退火算法

    Buried memory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  6. hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  7. HDU 4666 Hyperspace (最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  8. 2018 Multi-University Training Contest 10 CSGO(HDU - 6435)(最远曼哈顿距离)

    有 n 种主武器,m 种副武器.每种武器有一个基础分数k种属性值 X[i] . 选出一种主武器 mw 和一种副武器 sw,使得两种武器的分数和 + 每个属性的差值尽量大.(参考下面的式子) 多维的最远 ...

  9. 【23.68%】【hdu 2871】Memory Control

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

随机推荐

  1. Case When Exists SQL

    The Case-When-Exists expression in Oracle is really handy. Here's an example of how to use it in a s ...

  2. Web serviser请求通道在等待 00:00:59.6479648 以后答复时超时。增加传递给请求调用的超时值,或者增加绑定上的 SendTimeout 值。分配给此操作的时间可能是更长超时的一部分。

    可以把sendTimeout调长一点试试 .net webService 中: 设置这些参数,延长连接时间, closeTimeout="00:10:00" openTimeout ...

  3. spark性能调优:资源优化

    在开发完Spark作业之后,就该为作业配置合适的资源了.Spark的资源参数,基本都可以在spark-submit命令中作为参数设置.很多Spark初学者,通常不知道该设置哪些必要的参数,以及如何设置 ...

  4. 一款jQuery实现重力弹动模拟效果特效,弹弹弹,弹走IE6

    一款jQuery实现重力弹动模拟效果特效 鼠标经过两块黑色div中间的红色线时,下方的黑快会突然掉落, 并在掉落地上那一刻出现了弹跳的jquery特效效果,非常不错,还兼容所有的浏览器, 适用浏览器: ...

  5. 使用PyInstaller将Python程序打包成一个单独的exe文件

    1. 安装步骤略过 网上教程多 2. 用cmd进入PyInstaller的目录 然后执行以下命令: python pyinstaller.py -F C:\test.py 以上命令需要把Python目 ...

  6. rails中ActionController::InvalidAuthenticityToken解决办法

    Ror代码 class FooController < ApplicationController protect_from_forgery :except => :index # you ...

  7. 多线程基本概论multithread

    多线程 基本概念 进程 进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内 通过 活动监视器 可以查看 Mac 系统中所开启的进程 线程 进程要想 ...

  8. 刀哥多线程全局队列gcd-09-global_queue

    全局队列 是系统为了方便程序员开发提供的,其工作表现与并发队列一致 全局队列 & 并发队列的区别 全局队列 没有名称 无论 MRC & ARC 都不需要考虑释放 日常开发中,建议使用& ...

  9. Objective-C关于数据处理

    本文介绍如何在Objective-C中操作数据.我们将使用数组.指针.字符串等. 数组是数据项的一个集合,这些数据项叫做元素,我们可以用一个数组索引来引用元素.例如,如果把数字存储在一个名为array ...

  10. esp和ebp详解

    最近在研究栈帧的结构,但总是有点乱,所以写了一个小程序来看看esp和ebp在栈帧中的作用.这个程序如下: 这个程序很简单,就是求两个数的值,然后输出即可.所以首先把它用gcc编译链接成a.out,进入 ...