artemgf

Пусти козла в огород

Apr 5th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <math.h>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <cmath>
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     double n, r;
  15.  
  16.     cin >> n >> r;
  17.     cout.precision(3);
  18.     cout.setf(ios::fixed);
  19.     if (n / 2.0 >= r)
  20.         cout << M_PI*r*r;
  21.     else
  22.     {
  23.         if (sqrt(n*n + n*n) / 2 < r)
  24.             cout << n*n;
  25.         else
  26.         {
  27.             double a = 2.0*acos((n / 2.0) / r);
  28.             double l = 2.0*r*sin(a / 2.0);
  29.             double S = (a / 2.0)*r*r - (l*n / 2.0) / 2.0;
  30.             cout << (M_PI*r*r) - 4.0 * S;
  31.         }
  32.     }
  33.  
  34.     _getch();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment