Guest User

Untitled

a guest
May 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <utility>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. pair <double, int> l[1000000];
  9.  
  10. struct Point
  11. {
  12.   double x, y;
  13.   Point() {}
  14.   Point(double a, double b) {x = a, y = b;}
  15. };
  16.  
  17. int main()
  18. {
  19.   int n, i, k = 0;
  20.   double s = 0, r1, r2, lf = 0;
  21.   double rmin = 1000001, rmax = 0;
  22.   scanf("%d", &n);
  23.   for ( i = 0; i < n; i++)
  24.   {
  25.     scanf("%lf %lf %lf %lf", &r1, &r2, &l[2 * i].first, &l[2 * i + 1].first);
  26.     rmin = min(rmin, r1);
  27.     rmax = max(rmax, r2);  
  28.     l[2 * i].second = 1;
  29.     l[2 * i + 1].second = 2;
  30.     if ( l[2 * i].first > l[2 * i + 1].first )
  31.     {
  32.       k++;
  33.       lf = max(lf, l[2 * i].first);
  34.     }
  35.   }
  36.   sort(l, l + 2 * n);  
  37.   for ( i = 1; i < 2 * n; i++)
  38.   {
  39.     if ( k == n)
  40.     {
  41.       s += ((l[i].first - lf) * rmax * rmax - (l[i].first - lf) * rmin * rmin) / 2;  
  42.       lf = l[i].first;
  43.     }
  44.     if ( l[i].second == 1)
  45.     {  
  46.       k++;
  47.       lf = l[i].first;
  48.     }
  49.   }
  50.   printf("%10.lf", s);
  51.   return 0;                                  
  52. }
Add Comment
Please, Sign In to add comment