ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1159. Fence

who can help me???i've got WA for mant times
Posted by coma 12 Jun 2003 13:45
#include <stdio.h>
#include <math.h>

#define PI 3.1415926535

double a[101];
int n;

void init()
{
int i,k;
double t;
scanf("%d",&n);
k=1;
for (i=1;i<=n;i++)
 {
 scanf("%lf",&a[i]);
 if (a[i]>a[k])
  k=i;
 }
t=a[1];
a[1]=a[k];
a[k]=t;
}

double hl(double r,int k)
{
double p;
double s;
p=(a[k]+r+r)/2;
s=p*(p-a[k])*(p-r)*(p-r);
return (sqrt(s));
}

double find_s(int k,double r)
{
int i;
double s;
if (k==0)
 s=-hl(r,1);
else
 s=hl(r,1);
for (i=2;i<=n;i++)
 s=s+hl(r,i);
return (s);
}

double judge(int k,double r)
{
double deg;
int i;
double b,c;
if (k==0)
 deg=2*PI-acos(1-(a[1]*a[1])/(2*r*r));
else
 deg=acos(1-(a[1]*a[1])/(2*r*r));
for (i=2;i<=n;i++)
 deg=deg+acos(1-(a[i]*a[i])/(2*r*r));
return (deg);
}

void solve()
{
int i,k;
double high,low,l;
double mid;
low=a[1]/2;high=1000000;
k=0;
if (judge(1,low)>2*PI)
 k=1;
else
 k=0;
while (high-low>0.00001)
 {
 mid=(high+low)/2;
 l=judge(k,mid);
 if (k==1)
  {
  if (l>PI*2)
   low=mid;
  else
   high=mid;
  }
 if (k==0)
  {
  if (l>PI*2)
   high=mid;
  else
   low=mid;
  }
 }
printf("%.2lf\n",find_s(k,mid));
}

main()
{
int i;
double sum;
init();
sum=0;
for (i=2;i<=n;i++)
 sum=sum+a[i];
if (sum<=a[1])
 printf("0.00\n");
else
solve();
return 0;
}