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

stupid but works :)
Posted by pera-zdera 27 Sep 2005 13:44
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cstdlib>
#include <math.h>
#define PI 3.141592653589793238462643383279502884197169399375
using namespace std;
int main(int argc, char** argv){
    double a, l, angle = 0.0;
    cin >> a >> l;
    if (l <= (a/2.0))
        printf("%0.3f", (l*l*PI));
    else if (l >= (a*sqrt(2.0)/2.0))
        printf("%0.3f", (a*a));
    else {
        while (l*cos(angle) > (a/2.0)) angle += 0.0000001;
        printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle))));
    }
}
Re: stupid but works :)
Posted by Cyclops 2 Dec 2008 00:04
please explain :

else {
while (l*cos(angle) > (a/2.0)) angle += 0.0000001;
printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle))));
}

i don't understand with your way of thinking to get that calculation..
please explain to me..
to Cyclops
Posted by Imran Yusubov 7 Aug 2009 12:19
His solution is not stupid instead it is great I tried with mathematic way to find l to the point where the circle crosess the rect but every time i got WA.

l*cos(angle) -that means the length to the point where the circle crosses the rect-s side.At the begining it is equals to r but as we increase angel the cos(angel) decreases the value and we find the exact length.
and here ("%0.3f", 4.0*((a/2.0)*l*sin(angle) we find the are of triangles and add the are of sectors +(l*l*(PI/4.0-angle))...that is all ..if you don't understand again contact me with the problem name.. imran_yusubov@yahoo.com
Cyclops wrote 2 December 2008 00:04
please explain :

else {
while (l*cos(angle) > (a/2.0)) angle += 0.0000001;
printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle))));
}

i don't understand with your way of thinking to get that calculation..
please explain to me..

Edited by author 07.08.2009 12:19

Edited by author 07.08.2009 12:20
Re: to Cyclops
Posted by lightstone 17 May 2013 03:34
Why woudn`t you just use acos(a/(l*2)) to get an angle? ( its arc cos in the triangle we get there)

|\
| \
|  \
|   \ l
|    \
|a/2  \
|      \
|_______\