HDOJ 3007 Buried memory 增量法最小圓覆蓋

來源:互聯網
上載者:User

標籤:


增量法最小圓覆蓋,簡單模版

Buried memoryTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2541    Accepted Submission(s): 1365


Problem DescriptionEach person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.
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. 
InputThere are many test cases.Each case consists of a positive integer N(N<500,^V^,our great king might be a considerate lover) on a line followed by N lines giving the coordinates of N letters.Each coordinates have two numbers,x coordinate and y coordinate.N=0 is the end of the input file. 
OutputFor each case,there should be a single line in the output,containing three numbers,the first and second are x and y coordinates of the missile to launch,the third is the smallest radius the missile need to destroy all N letters.All output numbers are rounded to the second digit after the decimal point.
 
Sample Input
31.00 1.002.00 2.003.00 3.000
 
Sample Output
2.00 2.00 1.41
 
Source2009 Multi-University Training Contest 11 - Host by HRBEU 


/* ***********************************************Author        :CKbossCreated Time  :2014年12月29日 星期一 15時15分46秒File Name     :HDOJ3007.cpp************************************************ */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>using namespace std;const int maxn = 888;const double eps=1e-8;struct Point{double x,y;}pt[maxn];Point operator+(Point A,Point B) { return (Point){A.x+B.x,A.y+B.y}; }Point operator-(Point A,Point B) { return (Point){A.x-B.x,A.y-B.y}; }Point operator*(Point A,double p) { return (Point){A.x*p,A.y*p}; }Point operator/(Point A,double p) { return (Point){A.x/p,A.y/p}; }int n;int dcmp(double x){if(fabs(x)<eps) return 0;if(x>eps) return 1;else return -1;}double Cross(Point A,Point B) { return A.x*B.y-A.y*B.x; }double Dot(Point a,Point b) { return a.x*b.x+a.y*b.y; }double Length(Point a) { return sqrt(Dot(a,a)); }struct Circle{Point c; double r;};Circle CircumscribedCircle(Point p1,Point p2,Point p3){double Bx=p2.x-p1.x,By=p2.y-p1.y;double Cx=p3.x-p1.x,Cy=p3.y-p1.y;double D=2*(Bx*Cy-By*Cx);double cx=(Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D+p1.x;double cy=(Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D+p1.y;Circle c;c.c=(Point){cx,cy};c.r=Length(p1-c.c);return c;}void min_cover_circle(Point p[],int n,Circle& c){c.c=p[0]; c.r=0;for(int i=1;i<n;i++){if(dcmp(Length(p[i]-c.c)-c.r)>0){c.c=p[i]; c.r=0;for(int j=0;j<i;j++){if(dcmp(Length(p[j]-c.c)-c.r)>0){c.c=(Point){(p[i].x+p[j].x)/2,(p[i].y+p[j].y)/2};c.r=Length(p[j]-p[i])/2.;for(int k=0;k<j;k++){if(dcmp(Length(p[k]-c.c)-c.r)>0){c=CircumscribedCircle(p[i],p[j],p[k]);}}}}}}}int main(){    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);while(scanf("%d",&n)!=EOF&&n){for(int i=0;i<n;i++) scanf("%lf%lf",&pt[i].x,&pt[i].y);Circle c;min_cover_circle(pt,n,c);printf("%.2lf %.2lf %.2lf\n",c.c.x,c.c.y,c.r);}        return 0;}



HDOJ 3007 Buried memory 增量法最小圓覆蓋

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.