Advertisement
Mlxa

D.cpp

Mar 30th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using double_type = double;
  3. #define double double_type
  4. #define long int64_t
  5. using namespace std;
  6.  
  7. const double PI = atan2((double)0, (double)-1);
  8.  
  9. const double eps = 1e-12;
  10. const double inf = 1e+12;
  11.  
  12. bool double_equal(double a, double b) {
  13.     return abs(a - b) <= eps;
  14. }
  15.  
  16. bool double_less(double a, double b) {
  17.     return a < b - eps;
  18. }
  19.  
  20. bool double_greater(double a, double b) {
  21.     return a > b + eps;
  22. }
  23.  
  24.  
  25. struct point {
  26.     double x, y;
  27.    
  28.     point(double a, double b) :
  29.         x(a),
  30.         y(b) {}
  31.    
  32.     point() :
  33.         point(0, 0) {}
  34.    
  35.     point to(point v) {
  36.         return {v.x - x, v.y - y};
  37.     }
  38.    
  39.     point operator+(point v) {
  40.         return {v.x + x, v.y - y};
  41.     }
  42.    
  43.     point operator-(point v) {
  44.         return {x - v.x, y - v.y};
  45.     }
  46.    
  47.     double operator*(point v) {
  48.         return x * v.x + y * v.y;
  49.     }
  50.    
  51.     double operator%(point v) {
  52.         return x * v.y - y * v.x;
  53.     }
  54.    
  55.     double angle() {
  56.         return atan2(y, x);
  57.     }
  58.    
  59.     friend double angle(point a, point b) {
  60.         return atan2(a % b, a * b);
  61.     }
  62.    
  63.     double len2() {
  64.         return x * x + y * y;
  65.     }
  66.    
  67.     double len() {
  68.         return sqrt(len2());
  69.     }
  70.    
  71.     double dist2(point p) {
  72.         return to(p).len2();
  73.     }
  74.    
  75.     double dist(point p) {
  76.         return sqrt(dist2(p));
  77.     }
  78.    
  79.     bool small(point a, point b) {
  80.         return !double_less(to(a) * to(b), 0);
  81.     }
  82.    
  83.     bool operator==(point p) {
  84.         return double_equal(x, p.x) && double_equal(y, p.y);
  85.     }
  86.    
  87.     bool operator!=(point p) {
  88.         return !(operator==(p));
  89.     }
  90.    
  91.     friend istream &operator>>(istream &in, point &p) {
  92.         return in >> p.x >> p.y;
  93.     }
  94.    
  95.     friend ostream &operator<<(ostream &out, point p) {
  96.         return out << p.x << " " << p.y;
  97.     }
  98. };
  99.  
  100. struct line {
  101.     point f, s;
  102.    
  103.     line(point a, point b) :
  104.         f(a),
  105.         s(b) {
  106.         assert(a != b);
  107.     }
  108.    
  109.     line() :
  110.         f(),
  111.         s() {}
  112.    
  113.     double dist2(point p) {
  114.         double sq = p.to(f) % p.to(s);
  115.         return sq * sq / f.dist2(s);
  116.     }
  117.    
  118.     double dist(point p) {
  119.         return p.to(f) % p.to(s) / f.dist(s);
  120.     }
  121.    
  122.     bool have(point p) {
  123.         return double_equal(f.to(p) % f.to(s), 0);
  124.     }
  125. };
  126.  
  127. struct segment {
  128.     point f, s;
  129.    
  130.     segment(point a, point b) :
  131.         f(a),
  132.         s(b) {}
  133.    
  134.     segment() :
  135.         f(),
  136.         s() {}
  137.    
  138.     double dist2(point p) {
  139.         if (f == s) {
  140.             return f.dist2(p);
  141.         }
  142.         if (f.small(p, s) && s.small(p, f)) {
  143.             return line(f, s).dist2(p);
  144.         } else {
  145.             return min(p.dist2(f), p.dist2(s));
  146.         }
  147.     }
  148.    
  149.     double dist(point p) {
  150.         return sqrt(dist2(p));
  151.     }
  152.    
  153.     bool have(point p) {
  154.         return line(f, s).have(p) && !double_greater(p.to(f) * p.to(s), 0);
  155.     }
  156.    
  157.     bool check_intersect(segment o) {
  158.         if (have(o.f) || have(o.s) || o.have(f) || o.have(s)) {
  159.             return true;
  160.         }
  161.         point a = f;
  162.         point b = s;
  163.         point c = o.f;
  164.         point d = o.s;
  165.         return  double_less((a.to(b) % a.to(c)) * (a.to(b) % a.to(d)), 0) &&
  166.                 double_less((c.to(d) % c.to(a)) * (c.to(d) % c.to(b)), 0);
  167.     }
  168.    
  169.     double dist2(segment o) {
  170.         if (check_intersect(o)) {
  171.             return 0;
  172.         }
  173.         double a = dist2(o.f);
  174.         double b = dist2(o.s);
  175.         double c = o.dist2(f);
  176.         double d = o.dist2(s);
  177.         return min({a, b, c, d});
  178.     }
  179.    
  180.     double dist(segment o) {
  181.         return sqrt(dist2(o));
  182.     }
  183. };
  184.  
  185. int main() {
  186. #ifdef LC
  187.     assert(freopen("input.txt", "r", stdin));
  188. #else
  189.     assert(freopen("goat1.in", "r", stdin));
  190.     assert(freopen("goat1.out", "w", stdout));
  191. #endif
  192.     ios::sync_with_stdio(0);
  193.     cin.tie(0);
  194.     cout << fixed << setprecision(15);
  195.     cerr << fixed << setprecision(15);
  196.    
  197.     double d, r;
  198.     cin >> d >> r;
  199.     d /=- 2;
  200.    
  201.     if (r <= d) {
  202.         cout << PI * r * r << "\n";
  203.         return 0;
  204.     }
  205.     double cosa2 = d / r;
  206.     double sina2 = sqrt(1 - cosa2 * cosa2);
  207.     double a = asin(sina2) * 2;
  208.     cout << PI * r * r - 2 * r * r * (a - sin(a)) << "\n";
  209.     return 0;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement