|  | 
|  | 
| вернуться в форум | stupid but works :) #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 :) 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 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  please explain :Edited by author 07.08.2009 12:19 Edited by author 07.08.2009 12:20
 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..
Re: to  Cyclops 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  \
 |      \
 |_______\
 | 
 | 
|