Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 682 Accepted Submission(s): 174
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
const double eps=1e-10;
double m[110][2];
int n;
const double PI=acos(-1.0);
int jug(double mid)
{
double sum=0.0;
int i;
double temp;
for(i=0;i<n;i++)
{
if(mid>(m[i][0]+m[i][1])-eps) return 1;
if(mid<fabs(m[i][0]-m[i][1])+eps) return -1;
temp=(m[i][0]*m[i][0]+m[i][1]*m[i][1]-mid*mid)/(2.0*m[i][0]*m[i][1]);
sum+=acos(temp);
}
if(sum>PI*2.0+eps) return 1;
if(sum<PI*2.0-eps) return -1;
else return 0;
}
int main()
{
int i,T;
int iCase=0;
scanf("%d",&T);
double l,r,temp;
while(T--)
{
iCase++;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%lf",&m[i][1]);
m[i+1][0]=m[i][1];
}
m[0][0]=m[n][0];
bool flag=false;
double mid;
int temp1;
l=0;
r=20000;
while((r-l)>eps)
{
mid=(r+l)/2;
temp1=jug(mid);
if(temp1==0)
{
flag=true;
break;
}
if(temp1<0) l=mid;
else r=mid;
}
if(!flag) printf("Case %d: impossible\n",iCase);
else printf("Case %d: %.3lf\n",iCase,mid);
}
return 0;
}