Tarango

Infinite Game

Aug 2nd, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pi acos(-1.0)
  4.  
  5. double R,x1,x2,y;
  6.  
  7. double getArea(double r,double x1,double x2){
  8.     double cos2 = acos(x2*1.0/R);
  9.     double cos1 = acos(x1*1.0/R);
  10.     double res = R*(x2*sin(cos2) - x1*sin(cos1));
  11.     double tom = res - R*R*cos2 + R*R*cos1;
  12.     return tom;
  13. }
  14.  
  15. void solve1(){
  16.     double oditi,sam,ron,tom;
  17.     if(x1>=R){
  18.         oditi = pi*R*R;
  19.         tom = 0;
  20.         double brothersArea = abs(x2-x1)*y*2.0;
  21.         sam = ron = brothersArea/2.0;
  22.     }else if(x2>=R){
  23.         tom = getArea(R,x1,R);
  24.         oditi = pi*R*R - tom;
  25.         double brothersArea = abs(x2-x1)*y*2.0 - tom;
  26.         sam = ron = brothersArea/2.0;
  27.     }else{
  28.         tom = getArea(R,x1,x2);
  29.         oditi = pi*R*R - tom;
  30.         double brothersArea = abs(x2-x1)*y*2.0 - tom;
  31.         sam = ron = brothersArea/2.0;
  32.     }
  33.     printf("%.3lf %.3lf %.3lf %.3lf\n",oditi,sam,ron,tom);
  34. }
  35.  
  36. int main(){
  37.     int nCase;
  38.     scanf("%d",&nCase);
  39.     for(int cs = 1;cs<=nCase;cs++){
  40.         scanf("%lf %lf %lf %lf",&R,&x1,&x2,&y);
  41.         if(x1>x2) swap(x1,x2);
  42.         solve1();
  43.     }
  44.     return 0;
  45. }
Add Comment
Please, Sign In to add comment