EntropyIncreaser

CodeForces 1C Ancient Berland Circus

Jan 6th, 2018
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. typedef double num;
  7.  
  8. struct vec2d {
  9.     num x, y;
  10.  
  11.     vec2d() {}
  12.  
  13.     vec2d(num x, num y) : x(x), y(y) {}
  14.  
  15.     num len() const {
  16.         return sqrt(x * x + y * y);
  17.     }
  18.  
  19.     vec2d rot90() const {
  20.         return vec2d(-y, x);
  21.     }
  22.  
  23.     vec2d rot90(const vec2d& v) const {
  24.         return (*this - v).rot90() + v;
  25.     }
  26.  
  27.     vec2d operator-() const {
  28.         return vec2d(-x, -y);
  29.     }
  30.  
  31.     vec2d operator+(const vec2d& v) const {
  32.         return vec2d(x + v.x, y + v.y);
  33.     }
  34.  
  35.     vec2d operator-(const vec2d& v) const {
  36.         return vec2d(x - v.x, y - v.y);
  37.     }
  38.  
  39.     vec2d operator+=(const vec2d& v) {
  40.         x += v.x;
  41.         y += v.y;
  42.         return *this;
  43.     }
  44.  
  45.     vec2d operator-=(const vec2d& v) {
  46.         x -= v.x;
  47.         y -= v.y;
  48.         return *this;
  49.     }
  50.  
  51.     vec2d operator*(num a) const {
  52.         return vec2d(x * a, y * a);
  53.     }
  54.  
  55.     vec2d operator/(num a) const {
  56.         return vec2d(x / a, y / a);
  57.     }
  58.  
  59.     num operator^(const vec2d& v) const {
  60.         return x * v.x + y * v.y;
  61.     }
  62.  
  63.     num operator*(const vec2d& v) const {
  64.         return x * v.y - y * v.x;
  65.     }
  66.  
  67.     friend vec2d operator*(num a, const vec2d& v) {
  68.         return vec2d(a * v.x, a * v.y);
  69.     }
  70.  
  71.     num angle(vec2d u, vec2d v) const {
  72.         u -= *this;
  73.         v -= *this;
  74.         return acos((u / u.len()) ^ (v / v.len()));
  75.     }
  76.  
  77.     friend vec2d intersect(const vec2d& p1, const vec2d& p2, const vec2d& q1, const vec2d& q2) {
  78.         num a1 = (q1 - p1) * (q2 - q1), a2 = (p2 - q1) * (q2 - p2);
  79.         return (p2 - p1) * a1 / (a1 + a2) + p1;
  80.     }
  81. };
  82.  
  83. const num EPS = 1e-5, PI2 = 6.2831853072;
  84.  
  85. int main() {
  86.     vec2d a, b, c, mid1, mid2, anc1, anc2, center;
  87.     scanf("%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y);
  88.     mid1 = (a + b) / 2;
  89.     anc1 = b.rot90(mid1);
  90.     mid2 = (b + c) / 2;
  91.     anc2 = c.rot90(mid2);
  92.     center = intersect(mid1, anc1, mid2, anc2);
  93.     for (int n = 3; n <= 100; ++n) {
  94.         num alpha = PI2 / n, t;
  95.         t = center.angle(a, b) / alpha;
  96.         if (fabs(t - round(t)) > EPS)
  97.             continue;
  98.         t = center.angle(b, c) / alpha;
  99.         if (fabs(t - round(t)) > EPS)
  100.             continue;
  101.         num r = (center - a).len();
  102.         printf("%.9lf\n", r * r * n * sin(alpha) / 2);
  103.         break;
  104.     }
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment