(hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

时间:2021-05-29 02:28:10

称号:

Maple trees

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 177 Accepted Submission(s): 63
 
Problem Description
There are a lot of trees in HDU. Kiki want to surround all the trees with the minimal required length of the rope . As follow, 
(hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)
To make this problem more simple, consider all the trees are circles in a plate. The diameter of all the trees are the same (the diameter of a tree is 1 unit). Kiki can calculate the minimal length of the rope , because it's so easy for this smart girl.
But we don't have a rope to surround the trees. Instead, we only have some circle rings of different radius. Now I want to know the minimal required radius of the circle ring. And I don't want to ask her this problem, because she is busy preparing for the examination.
As a smart ACMer, can you help me ?
(hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)
 
Input
The input contains one or more data sets. At first line of each input data set is number of trees in this data set n (1 <= n <= 100), it is followed by n coordinates of the trees. Each coordinate is a pair of integers, and each integer is in [-1000, 1000], it means the position of a tree’s center. Each pair is separated by blank.
Zero at line for number of trees terminates the input for your program.
 
Output
Minimal required radius of the circle ring I have to choose. The precision should be 10^-2.
 
Sample Input
2
1 0
-1 0
0
 
Sample Output
1.50
 
Author
zjt
 
 
Recommend
lcy
 

题目分析:

求凸包的最小覆盖圆的半径。事实上就是在求完凸包以后再求一下最小覆盖圆即可了。

这道题须要用到下面的一些知识:

1、关于钝角三角形,假设c是斜边,那么必定有a^2 + b^2 < c^2的证明。

(hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

2、由三角形的三个顶点求一个三角形的面积。

已知三角形△A1A2A3的顶点坐标Ai ( xi , yi ) ( i =1, 2, 3) 。该三角形的面积为:

  S =  ( (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) ) / 2 ;

  △A1A2A3 边界构成逆时针回路时取+ , 顺时针时取 -。

  另外在求解的过程中。不须要考虑点的输入顺序是顺时针还是逆时针,相除后就抵消了。

3、

 凸包+最小圆覆盖
枚举随意3点找其最小覆盖圆
(当为钝角三角形时不是外接圆,而是以其最长边为直径的圆)。
当为外接圆时,半径公式为r=abc/4s;(推导为例如以下:
由正弦定理,a/sinA=b/sinB=c/sinC=2R,得sinA=a/(2R),
又三角形面积公式S=(bcsinA)/2,所以S=(abc)/(4R),故R=(abc)/(4S).

这道题还须要注意的是:

1、在使用完graham求最小凸包以后。尽量让这个凸包闭合。即p[n] = p[0]。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const double epsi = 1e-8;
const double pi = acos(-1.0);
const int maxn = 101; struct PPoint{//结构体尽量不要定义成Point这样的,容易和C/C++本身中的变量同名
double x;
double y; PPoint(double _x = 0,double _y = 0):x(_x),y(_y){ } PPoint operator - (const PPoint& op2) const{
return PPoint(x - op2.x,y - op2.y);
} double operator^(const PPoint &op2)const{
return x*op2.y - y*op2.x;
}
}; inline int sign(const double &x){
if(x > epsi){
return 1;
} if(x < -epsi){
return -1;
} return 0;
} inline double sqr(const double &x){
return x*x;
} inline double mul(const PPoint& p0,const PPoint& p1,const PPoint& p2){
return (p1 - p0)^(p2 - p0);
} inline double dis2(const PPoint &p0,const PPoint &p1){
return sqr(p0.x - p1.x) + sqr(p0.y - p1.y);
} inline double dis(const PPoint& p0,const PPoint& p1){
return sqrt(dis2(p0,p1));
} int n;
PPoint p[maxn];
PPoint convex_hull_p0; inline bool convex_hull_cmp(const PPoint& a,const PPoint& b){
return sign(mul(convex_hull_p0,a,b)>0)|| (sign(mul(convex_hull_p0,a,b)) == 0 && dis2(convex_hull_p0,a) < dis2(convex_hull_p0,b));
} int convex_hull(PPoint* a,int n,PPoint* b){
int i;
for(i = 1 ; i < n ; ++i){
if(sign(a[i].x - a[0].x) < 0 || (sign(a[i].x - a[0].x) == 0 && sign(a[i].y - a[0].y) < 0)){
swap(a[i],a[0]);
}
} convex_hull_p0 = a[0];//这两行代码不要顺序调换了..否则会WA
sort(a,a+n,convex_hull_cmp); b[0] = a[0];
b[1] = a[1];
int newn = 2;
for(i = 2 ; i < n ; ++i){
while(newn > 1 && sign(mul(b[newn-1],b[newn-2],a[i])) >= 0){
newn--;
} b[newn++] = a[i];
} return newn;
} /**
* 有一个三角形的三个点来计算这个三角形的面积
*/
double crossProd(PPoint A, PPoint B, PPoint C) {
return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);
} int main(){
while(scanf("%d",&n)!=EOF,n){
int i;
for(i = 0 ; i < n ; ++i){
scanf("%lf %lf",&p[i].x,&p[i].y);
} /**
* 处理节点数仅仅有1、2的情况
*/
if(n == 1){
printf("0.50\n");
continue;
}
if(n == 2){
printf("%.2lf\n",dis(p[0],p[1])/2 + 0.5);
continue;
} /**
* 当结点数>=3时,用graham算法来求最小凸包
*/
n = convex_hull(p,n,p);
p[n] = p[0];//记得要收尾相接,否则可能会出错 int j;
int k; double maxr = -1;//用于求最小覆盖圆的半径
double r;
/**
* 枚举凸包中的随意三个点.
* 假设这三个点形成的外接圆的半径最大,
* 那么这个就是我们所要找的凸包的最小覆盖圆
*/
for(i = 0 ; i < n ; ++i){
for(j = i+1 ; j < n ; ++j){
for(k = j+1 ; k <= n ; ++k){//注意,这里的k是 <= n
double a = dis(p[i],p[j]);
double b = dis(p[i],p[k]);
double c = dis(p[j],p[k]); //假设这三个点所形成的是钝角三角形
if(a*a+b*b < c*c || a*a+c*c < b*b || b*b+c*c < a*a){
r = max(max(a,b),c)/2;//那么这时候的半径等于最长边的一半
}else{//假设是直角三角形||锐角三角形
double s = fabs(crossProd(p[i],p[j],p[k]))/2;//由定理1求得面积
r = a*b*c/(4*s);//三角形的外接圆公式
} if(maxr < r){//假设眼下存储的最大半径<当前外接圆的半径
maxr = r;//则更新眼下的最大半径
}
}
}
}
printf("%.2lf\n",maxr + 0.5);//输出凸包的最小覆盖圆的最大半径
} return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

(hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)的更多相关文章

  1. &lpar;hdu step 7&period;1&period;7&rpar;Wall&lpar;求凸包的周长——求将全部点围起来的最小凸多边形的周长&rpar;

    题目: Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  2. &lpar;hdu step 7&period;1&period;6&rpar;最大三角形&lpar;凸包的应用——在n个点中找到3个点&comma;它们所形成的三角形面积最大&rpar;

    题目: 最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  3. Maple trees(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)

    HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意:  给一个序列由 ...

  5. HDU - 1392 Surround the Trees &lpar;凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  6. HDU 1392 Surround the Trees &lpar;凸包周长&rpar;

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

  7. HDU 1392 Surround the Trees&lpar;凸包&ast;计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

  8. hdu 1392 Surround the Trees 凸包模板

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. hdu 1392 Surround the Trees &lpar;凸包&rpar;

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

随机推荐

  1. jquery combobox

    主要实现的功能有. 1.点击标签,显示所有数据源 2.在text中输入文本,模糊匹配. 3.配置是否必须要选择. 4.添加选中时的事件. 具体描述如下. combobox原型属性:        原型 ...

  2. QT学习入门笔记

    系统路径 path 添加dll路径,如D:\QT\5.4\mingw491_32. .pro 文件添加 QT +=  widgets,否则出现qapplication no such file or ...

  3. 第二章 约束和排序数据(SQL基础)

    第二章 约束和排序数据 1. 在 emp 表中选择工资介于 1500 到 2500 的员工的信息:                注意:使用 between 下边界 and 上边界时,条件包括边界值: ...

  4. apache服务器php程序

    1.全是.php结尾的.如何首页是index 2.安装完apache,如果输入 http://localhost:50/ 若出现 it works ,代表apache运作正常

  5. ROADS&plus;dijkstra的灵活运用&plus;POJ

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10742   Accepted: 3949 Descriptio ...

  6. 简单查询plan

    -> alter session set statistics_level=all; select /*+ gathe_plan_statistics */ * from ts.ts_recor ...

  7. 【转】花开正当时,十四款120&sol;128GB SSD横向评测

    原文地址:http://www.expreview.com/19604-all.html SSD横评是最具消费指导意义的评测文章,也是各类热门SSD固态硬盘的决斗疆场.SSD评测在行业内已经有不少网站 ...

  8. 既然选择了远方,便只顾风雨兼程--myvue

    浅谈以下vue的模式,其实vue的模式跟react是一样的,都是MVVM模式,就是直接数据和视图之间的切换 如果单纯这样认识的话,和angular相比较起来,vue就简单的很多,但是事实情况并不是这样 ...

  9. 用log4net记录日志信息

    在.net中用log4net记录日志信息,已经是很平常的事情了. log4net下载:http://logging.apache.org/log4net/download_log4net.cgi 百度 ...

  10. Codeforces A - Bear and Prime 100(交互题)

    A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表: ...