Guest User

Untitled

a guest
May 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 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. double Less(Point a, Point b)
  18. {
  19.   return (a.first < a.first);
  20. }
  21.  
  22. int main()
  23. {
  24.   int n, i, k = 0;
  25.   double s = 0, r1, r2, lf = 0;
  26.   double rmin = 1000001, rmax = 0;
  27.   scanf("%d", &n);
  28.   for ( i = 0; i < n; i++)
  29.   {
  30.     scanf("%lf %lf %lf %lf", &r1, &r2, &l[2 * i].first, &l[2 * i + 1].first);
  31.     rmin = min(rmin, r1);
  32.     rmax = max(rmax, r2);  
  33.     l[2 * i].second = 1;
  34.     l[2 * i + 1].second = 2;
  35.     if ( l[2 * i].first > l[2 * i + 1].first )
  36.     {
  37.       k++;
  38.       lf = max(lf, l[2 * i].first);
  39.     }
  40.   }
  41.   sort(l, l + 2 * n, Less);  
  42.   for ( i = 1; i < 2 * n; i++)
  43.   {
  44.     if ( k == n)
  45.     {
  46.       s += ((l[i].first - lf) * rmax * rmax - (l[i].first - lf) * rmin * rmin) / 2;  
  47.       lf = l[i].first;
  48.     }
  49.     if ( l[i].second == 1)
  50.     {  
  51.       k++;
  52.       lf = l[i].first;
  53.     }
  54.   }
  55.   printf("%10.lf", s);
  56.   return 0;                                  
  57. }
Add Comment
Please, Sign In to add comment