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 ...
随机推荐
- 获取屏幕分辨率(C#)
C#获取屏幕分辨率的方法 static void Main(string[] args) { // 控制台程序,需要添加程序集: // using System.Drawing; // using S ...
- Cassandra 的压缩策略STCS,LCS 和 DTCS
更新说明: 本文编写时最新的Cassandra版本为2.2,最新的稳定版本为2.1.8 2016年6月23日,增加一篇译文,当下最新版本为3.7 最新的Cassandra 2.1 或者更高的版本支持3 ...
- [Linux] Ubuntu Server 12.04 LTS 平台上搭建WordPress(Nginx+MySQL+PHP) Part IV
接下来我们去下载 WorePress 用最新的 3.7.1 下载地址是:http://cn.wordpress.org/wordpress-3.7.1-zh_CN.zip 我们先建立一个文件夹 /va ...
- phpcms 的实用相关接口,函数,调用方法
常用函数 , 打开include/global.func.php,下面存放一些公共函数view plaincopy to clipboardprint? strip_tags() 调用内容过滤html ...
- JqueryUI
http://jqueryui.com/ http://www.runoob.com/jqueryui/jqueryui-tutorial.html
- python实现 _ 图书馆书籍到期之前_自动邮件提醒
一共两个脚本: 第一个是[借书完毕以及借书信息有变更(续借等)]的时候需要执行的脚本:实现模拟登陆,同时最新的借书信息的下载到本地文本:之所以没有这样做,是因为如果每次爬取一遍的话,需要每次输入一遍验 ...
- 在Ubuntu下设置环境变量
在Ubuntu中有如下几个文件可以设置环境变量 /etc/profile:在登录时,操作系统定制用户环境时使用的第一个文件,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. /e ...
- ado.net的5个主要对象
connection 连接对象 command 命令对象,指示要执行的命令和存储过程! datareader是一个向前的只读的数据流. dataadapter是功能强大的适陪器,支持增删改查的功能 d ...
- SQL语句中各种数据类型转换方法总结
1.Access 每个函数都可以强制将一个表达式转换成某种特定数据类型. 语法 CBool(expression) CByte(expression) CCur(expression) CDate(e ...
- SQL 执行顺序
SQL 是一种声明式语言,与其他语言相比它的最大特点是执行顺序-并非按照语法顺序来执行.因此很多程序猿看到SQL就头疼,我之前也是这样,后来看到一篇文章后豁然开朗-地址. 理解了SQL的执行顺序无疑对 ...