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++求最大公约数
题目内容:求两个正整数的最大公约数. 输入描述:输入数据含有不多于50对的数据,每对数据由两个正整数(0<n1,n2<232)组成. 输出描述:对于每组数据n1和n2,计算最大公约数,每个 ...
- ajax使用。
<script> function createAjax(){ var request=false; //window对象中有XMLHttpRequest存在就是非IE,包括(IE7,IE ...
- Telerik XML 数据源绑定的问题
Telerik GridView 默认的 XElement 数据源的直接绑定,会导致内置的sort, filter ,group等功能无法使用. 原因在于Telerik GridView的那些功能是根 ...
- open/fopen read/fread write/fwrite区别
fopen /open区别 UNIX环境下的C 对二进制流文件的读写有两套班子:1) fopen,fread,fwrite ; 2) open, read, write这里简单的介绍一下他们的区别.1 ...
- java 通过zxing生成二维码
1.基本类提供二维码生成工具类 package com.green.util; import java.awt.image.BufferedImage; import java.io.ByteArra ...
- hdu 2034 人见人爱A-B
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2034 人见人爱A-B Description 参加过上个月月赛的同学一定还记得其中的一个最简单的题目, ...
- ajax & jsonp & img
ajax 是一种请求服务器的方式,核心是XMLHttpRequest对象: 优点是无需刷新页面, 缺点是不能跨域请求. /* * Ajax direacted by Zakas * * Ajax.ge ...
- SQLite之读取数据库内容
1.打开已有数据库. //打开数据库 - (BOOL )openDB {// 红色部分修改为自己的数据库路径 return (SQLITE_OK == sqlite3_open([@"/Us ...
- Entity Framework 插入数据出现重复插入(导航属性硬是要查再一遍???????)
问题: Artist artmodel = new Artist(); artmodel.user = uinfo; _artiests.Add(artmodel); 新增一条Artist记录,但是同 ...
- SQLite函数详解之二
sqlite3支持的数据类型: NULL.INTEGER.REAL.TEXT.BLOB 但是,sqlite3也支持如下的数据类型 smallint 16位整数 integer ...