hdu 3007 Buried memory 最远点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007
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.
#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 最远点对的更多相关文章
- HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)
Problem Description Each person had do something foolish along with his or her growth.But,when he or ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- HDU - 3007 Buried memory
传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...
- 【HDOJ】3007 Buried memory
1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示 ...
- HDU 3007 模拟退火算法
Buried memory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace (最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 2018 Multi-University Training Contest 10 CSGO(HDU - 6435)(最远曼哈顿距离)
有 n 种主武器,m 种副武器.每种武器有一个基础分数k种属性值 X[i] . 选出一种主武器 mw 和一种副武器 sw,使得两种武器的分数和 + 每个属性的差值尽量大.(参考下面的式子) 多维的最远 ...
- 【23.68%】【hdu 2871】Memory Control
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...
随机推荐
- Dynamic Prompt Table for Record Field on PeopleSoft Page
Sometimes a situation in project work arises to have a dynamic prompt table for record fields on Peo ...
- spark streaming kafka1.4.1中的低阶api createDirectStream使用总结
转载:http://blog.csdn.net/ligt0610/article/details/47311771 由于目前每天需要从kafka中消费20亿条左右的消息,集群压力有点大,会导致job不 ...
- PHP代码优化的53个细节
PHP代码优化的53个细节,常见而重要的php优化策略. 用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一 ...
- 从零开始之ecshop基础篇(17)
目标:基于自定义的mvc框架开发的案例(项目) 项目周期 需求分析 典型的业务逻辑: 电子商务:商城(京东),B2C,C2C(淘宝),团购,秒杀,代购 内容管理:新浪门户类,优酷视频管理, ...
- dede 单表模型动态浏览设置 arclistsg arc.sglistview.class.php
比如,分类信息,内容页默认都是生成静态的,如果有需要设为动态访问的,可以参考如下方法: arclistsg 标签,单表独立模型的文档列表调用标记 方法一: 在arclist标签使用中,其对应主表ded ...
- WordPress默认栏目设置
WordPress是一个注重美学.易用性和网络标准的个人信息发布平台,是全球使用最多的博客系统,只需要在系统后台做一些简单的设计,基本就能实现我们日常个性化发布个人信息的需求,而博客后台的使用其实很简 ...
- Java实现猜数游戏
利用Math.random()方法产生1~100的随机整数,利用JOptionPane.showInputDialog()方法产生一个输入对话框,用户可以输入所猜的数.若所猜的数比随机生成的数大,则显 ...
- svn的使用!!!
1.SVN:subversion(子级源代码版本控制管理软件) 2.SVN的作用 (1)避免开发同一项目不会出现代码覆盖. (2)同一文件可以创建许多不同的版本,并可以随时查看不同版本的内容. (3) ...
- SQL Server 基础:拾遗
1.一条完整的sql语句: select top | distinct 字段, 表达式, 函数, ... from 表表达式 where 筛选条件 group by 分组条件 having 筛选条件 ...
- Android程序完全退出的三种方法
很多网友可能发现自己的Android程序有很多Activity,比如说主窗口A,调用了子窗口B,在B中如何关闭整个Android应用程序呢? 这里Android123给大家三种比较简单的方法实现. 首 ...