hdu2215(最小覆盖圆)

Maple trees

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1578    Accepted Submission(s):
488

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,

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 ?

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

题意:用一个最小的圆把所有的点都圈在里边,点可以在圆上,每个点的半径为0.50

  1 #include<stdio.h>
  2 #include<math.h>
  3 #define PI acos(-1.0)
  4 struct   TPoint
  5 {
  6     double x,y;
  7 }a[1005],d;
  8 double r;
  9 double   distance(TPoint   p1,   TPoint   p2)
 10 {
 11     return (sqrt((p1.x-p2.x)*(p1.x -p2.x)+(p1.y-p2.y)*(p1.y-p2.y)));
 12 }
 13 double multiply(TPoint   p1,   TPoint   p2,   TPoint   p0)
 14 {
 15     return   ((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));
 16 }
 17 void MiniDiscWith2Point(TPoint   p,TPoint   q,int   n)
 18 {
 19     d.x=(p.x+q.x)/2.0;
 20     d.y=(p.y+q.y)/2.0;
 21     r=distance(p,q)/2;
 22     int k;
 23     double c1,c2,t1,t2,t3;
 24     for(k=1; k<=n; k++)
 25     {
 26         if(distance(d,a[k])<=r)
 27             continue;
 28         if(multiply(p,q,a[k])!=0.0)
 29         {
 30             c1=(p.x*p.x+p.y*p.y-q.x*q.x-q.y*q.y)/2.0;
 31             c2=(p.x*p.x+p.y*p.y-a[k].x*a[k].x-a[k].y*a[k].y)/2.0;
 32
 33             d.x=(c1*(p.y-a[k].y)-c2*(p.y-q.y))/((p.x-q.x)*(p.y-a[k].y)-(p.x-a[k].x)*(p.y-q.y));
 34             d.y=(c1*(p.x-a[k].x)-c2*(p.x-q.x))/((p.y-q.y)*(p.x-a[k].x)-(p.y-a[k].y)*(p.x-q.x));
 35             r=distance(d,a[k]);
 36         }
 37         else
 38         {
 39             t1=distance(p,q);
 40             t2=distance(q,a[k]);
 41             t3=distance(p,a[k]);
 42             if(t1>=t2&&t1>=t3)
 43             {
 44                 d.x=(p.x+q.x)/2.0;
 45                 d.y=(p.y+q.y)/2.0;
 46                 r=distance(p,q)/2.0;
 47             }
 48             else if(t2>=t1&&t2>=t3)
 49             {
 50                 d.x=(a[k].x+q.x)/2.0;
 51                 d.y=(a[k].y+q.y)/2.0;
 52                 r=distance(a[k],q)/2.0;
 53             }
 54             else
 55             {
 56                 d.x=(a[k].x+p.x)/2.0;
 57                 d.y=(a[k].y+p.y)/2.0;
 58                 r=distance(a[k],p)/2.0;
 59             }
 60         }
 61     }
 62 }
 63
 64 void MiniDiscWithPoint(TPoint   pi,int   n)
 65 {
 66     d.x=(pi.x+a[1].x)/2.0;
 67     d.y=(pi.y+a[1].y)/2.0;
 68     r=distance(pi,a[1])/2.0;
 69     int j;
 70     for(j=2; j<=n; j++)
 71     {
 72         if(distance(d,a[j])<=r)
 73             continue;
 74         else
 75         {
 76             MiniDiscWith2Point(pi,a[j],j-1);
 77         }
 78     }
 79 }
 80 int main()
 81 {
 82     int i,n;
 83     while(scanf("%d",&n)&&n)
 84     {
 85         for(i=1; i<=n; i++)
 86             scanf("%lf %lf",&a[i].x,&a[i].y);
 87         if(n==1)
 88         {
 89             printf("0.50\n");
 90             continue;
 91         }
 92
 93         r=distance(a[1],a[2])/2.0;
 94         d.x=(a[1].x+a[2].x)/2.0;
 95         d.y=(a[1].y+a[2].y)/2.0;
 96         for(i=3; i<=n; i++)
 97         {
 98             if(distance(d,a[i])<=r)
 99                 continue;
100             else
101                 MiniDiscWithPoint(a[i],i-1);
102         }
103         printf("%.2lf\n",r+0.5);
104     }
105     return 0;
106 }

hdu2215(最小覆盖圆)

时间: 2024-08-03 09:41:06

hdu2215(最小覆盖圆)的相关文章

Maple trees(最小覆盖圆)

Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 222 Accepted Submission(s): 79   Problem Description There are a lot of trees in HDU. Kiki want to surround all the trees with the minim

zoj 1450 Minimal Circle 最小覆盖圆

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to find a circle which covers a set of points and has the minimal area. There will be no more than 100 points in one problem. 题意描述:找到一个最小圆能够包含到所有的二维坐标点. 算法

最小覆盖圆算法

最小圆覆盖,很经典的问题.题目大概是,平面上n个点,求一个半径最小的圆,能够覆盖所有的点. 算法有点难懂,于是讲讲我的理解. 如果要求一个最小覆盖圆,这个圆至少要由三个点确定.有一种算法就是任意取三个点作圆,然后判断距离圆心最远的点是否在圆内,若在,则完成:若不在则用最远点更新这个圆. 这里介绍的算法是,先任意选取两个点,以这两个点的连线为直径作圆.再以此判断剩余的点,看它们是否都在圆内(或圆上),如果都在,说明这个圆已经找到.如果没有都在:假设我们用的最开始的两个点为p[1],p[2],并且找

(hdu step 7.1.5)Maple trees(求凸包的最小覆盖圆的半径)

题目: 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 m

最小覆盖圆

给出一堆点,求一个面积(半径)最小的圆,使得所有点都在它的内部或边界上. 随机增量法是这样的.... 先随机打乱点的顺序...... 然后,我们假设已经得到了点 $1,2,...,i$ 的最小覆盖圆,我们要求出点 $1,2,...,i,i+1$ 的最小覆盖圆. 怎么做? 考虑点 $i+1$ ,分两种情况: 1.如果点 $i+1$ 在点 $1,2,...,i$ 的最小覆盖圆里面或边界上,那么点 $1,2,...,i,i+1$ 的最小覆盖圆就是点 $1,2,...,i$ 的最小覆盖圆. 证明: 假设

[matlab] 10.最小覆盖圆

clear all; close all; clc; n=100; p=rand(n,2); p1=p(1,:); %取第一行的值 P1点 p2=p(2,:); %取第二行的值 P2点 r=sqrt((p1(1)-p2(1))^2+(p1(2)-p2(2))^2)/2; %求两点半径 cenp=(p1+p2)/2; %求两点中点 for i=3:n newp=p(i,:); %从第三行开始 储存新的点 d=sqrt((cenp(1)-newp(1))^2+(cenp(2)-newp(2))^2)

平面点集的最小包围圆 hdu 3932

最小覆盖圆算法地址:http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066 平面点集的最小包围圆 1.           问题背景 考察固定在工作平台上的一直机械手,要捡起散落在不同位置的多个零件,并送到别的地方.那么,这只机械手的底座应该选在哪里呢?根据直觉,应该选在机械手需够着的那些位置的"中心".准确地讲,也就是包围这些点的那个最小圆的圆心----该位置的好处是,可使机械手的底座到它需要够着的那些点的最大距离最小化.于是可得如下问题:给

计算几何学习8

由于poj炸了 而题单上有很多poj的题 就先开始第二部分了 学习了两个固定算法 最小圆覆盖和平面上最近点对 平面上最近点对采用的是分治的思想 把一个x有序的序列分成A,B左右两部分 当得到A内最近点对距离,B类最近点对距离后 先更新大序列的答案ans A,B间最近点对的产生 显然在x坐标距离mid点不超过ans的区间内产生 我们把这段区间拿出来,对y排序 再逐对更新 值得注意的地方 1)为了确保速度 可以在第二次对y排序的时候采取对标号排序的方式 2)在枚举点对更新的时候注意在y差值 >= a

计算几何及其应用——解析几何

写在前面:刚学专业课的时候,记得有天突发奇想,心说高三数学的压轴题能不能写个程序跑出答案,这样岂不是解放了数万苦逼高三生的双手?但是当时也仅仅是停留在想法上面,因为高中的解析几何虽然步骤程序化,但是有时候需要灵巧的因式分解,感觉以目前的编程水平还是写不出来,但是了解到数学有一个分支——计算几何,专门利用计算机来进行几何计算的一门科学,并且还与计算机图形学.计算机视觉和图像处理.机器人.计算机辅助设计和制造等高深学科有着联系(摘自<计算几何与应用>导言),所以今天怀着激动的心情开始了这个专题的学