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 1084. Goat in the Garden

Show all messages Hide all messages

#include <stdio.h>
#include <math.h>
void main(){
double r,a,s,angl,cosa;
scanf("%lf %lf",&a,&r);
if (2*r<a) s=M_PI*r*r;
else if (sqrt(2)*r>a) s=a*a;
else{
  cosa=a/(2*r);
  angl=2*acos(cosa);
  angl=M_PI/2-angl;
  s=((a/2)*sqrt(r*r-(a*a)/4))+angl*r*r/2;
  }
printf("%.3lf\n",4*s);
}
> #include <stdio.h>
> #include <math.h>
> void main(){
> double r,a,s,angl,cosa;
> scanf("%lf %lf",&a,&r);
> if (2*r<a) s=M_PI*r*r;
> else if (sqrt(2)*r>a) s=a*a;
> else{
>   cosa=a/(2*r);
>   angl=2*acos(cosa);
>   angl=M_PI/2-angl;
>   s=((a/2)*sqrt(r*r-(a*a)/4))+angl*r*r/2;
>   }
> printf("%.3lf\n",4*s);
> }
i think my reply was too late. but for other people.
when using sqrt(2) or something which arguments are not integer, you should use -> sqrt(2.0) instead.
sqrt(2) ==> sqrt(2.0)
Thank you very much!!! I'd reciiving :"compilation error"...
But now all O.K.! ))