hdu 4033

现在还不怎么适应比赛的节奏啊,二分边长即可,余弦定理求角度即可,注意,要先判断所选取的边是否合法

View Code
#include<stdio.h>
#
include<string.h>
#
include<math.h>
#
include<stdlib.h>
const double pi = acos(-1.0);
const double expn
=1e-8;
double a[
110];
int n;
double get_angel(double x,double y,double z)
{
return acos((x*x+y*y-z*z)/(2*x*y));
}
int f(double x)
{
double res
=0,a1,a2;
for (int i=1; i<=n; i++)
{
a1
=a[i];
if (i<n) a2=a[i+1]; else a2=a[1];
if(x-a1-a2>expn) return 1;
if(fabs(x-a1-a2)<expn) return 1;
if(fabs(a1-a2)-x>expn) return -1;
if(fabs(fabs(a1-a2)-x)<expn) return -1;
res
+=get_angel(a1,a2,x);
}
if (fabs(res-pi*2)<expn) return 0;
if ((res - pi*2) > expn) return 1; else return -1;
}
double bsearch(double l,double r)
{
double mid;
for(int k=1;k<100;k++)
{
mid
=(l+r)/2;
int t
=f(mid);
if(t==0) return mid;
if(t>0) r=mid;
else l=mid;
}
return -1;
}
int main()
{
int t,cases
=1,i;
scanf(
"%d",&t);
while(t--)
{
scanf(
"%d",&n);
double max
=0;
for(i=1;i<=n;i++)
{
scanf(
"%lf",&a[i]);
if(a[i]>max)
max
=a[i];
}
double ans
=bsearch(0,2*max);
if(ans<0) printf("Case %d: impossible\n",cases++);
else printf("Case %d: %.3lf\n",cases++,ans);
}
return 0;
}

  

posted @ 2011-09-12 15:28  Because Of You  Views(265)  Comments(0Edit  收藏  举报