//1017 Stacking Cylinders
//By BodeSmile
//Start at : 2005-3-2 11:00
//Algorithm :
//note :

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

struct point
{
 double x,y;
};

bool comp(point a,point b)
{
 return a.x<b.x;
}

point New_Point(point a,point b,double r)//r为半径,并确保a的X<b的X
{
 double a1,a2,a3,a4,a5,a6,t;
 point temp;
 if(a.y==b.y)
 {
  temp.x=(a.x+b.x)/2;
  temp.y=a.y+sqrt((2*r)*(2*r)-(b.x-a.x)*(b.x-a.x)/4);
  return temp;
 }
 else if(a.y<b.y)
 {
  a1=(sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)))/2;
  a2=sqrt(4*r*r-a1*a1);
  a3=(a2*(b.y-a.y)/(b.x-a.x));
  a4=a1-a3;
  a5=(a4*(b.x-a.x))/(2*a1);
  a6=sqrt(4*r*r-a5*a5);
  temp.x=a.x+a5;
  temp.y=a.y+a6;
  return temp;
 }
 else
 {
  t=a.y;
  a.y=b.y;
  b.y=t;

  a1=(sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)))/2;
  a2=sqrt(4*r*r-a1*a1);
  a3=(a2*(b.y-a.y)/(b.x-a.x));
  a4=a1-a3;
  a5=(a4*(b.x-a.x))/(2*a1);
  a6=sqrt(4*r*r-a5*a5);
  temp.x=b.x-a5;
  temp.y=a.y+a6;
  return temp;
 }

}

int main ()
{
 int maxN;
 int i;
 point p[20];


 while(cin>>maxN&&maxN!=0)
 {
  for(i=0;i<maxN;i++)
  {
   cin>>p[i].x;
   p[i].y=1.0;
  }
  sort(p,p+maxN,comp);
  printf("%.4f ",(p[0].x+p[maxN-1].x)/2);
  while(maxN>1)
  {
  for(i=0;i<maxN-1;i++)
  {
   p[i]=New_Point(p[i],p[i+1],1.0);
  }
  maxN--;
  }
  printf("%.4f\n",p[0].y);
 }

 return 0;
}

SNOJ上的 1017 Stacking Cylinders —— 我是第一个提交的啊!

相关文章:

  • 2022-12-23
  • 2022-02-25
  • 2021-09-28
  • 2021-12-16
  • 2022-12-23
  • 2021-08-12
  • 2022-01-22
  • 2021-04-19
猜你喜欢
  • 2021-11-29
  • 2022-02-19
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-07-30
相关资源
相似解决方案