SHARE
TWEET

2 J

kot_mapku3 Jun 2nd, 2020 655 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cmath>
  5. #include <vector>
  6.  
  7. #define ll long long
  8. #define even(a) a%2==0?0:1
  9. void speed() {
  10.     std::ios::sync_with_stdio(false);
  11.     std::cin.tie(nullptr);
  12.     std::cout.tie(nullptr);
  13. }
  14.  
  15. using namespace std;
  16.  
  17. int length(int l1, int r1, int l2, int r2) {
  18.     int l = max(l1, l2);
  19.     int r = min(r1, r2);
  20.  
  21.     if (r < l) return 0; // пересечения нет
  22.     else return r - l;
  23.  
  24.     return 0;
  25. }
  26.  
  27. int main() {
  28.     speed();
  29.  
  30.     int x1,x2,x3,x4;
  31.     int y1,y2,y3,y4;
  32.  
  33.     cin >> x1 >> y1 >> x2 >> y2;
  34.     cin >> x3 >> y3 >> x4 >> y4;
  35.  
  36.     if (x2 < x1) swap(x1,x2);
  37.     if (x4 < x3) swap(x3,x4);
  38.     if (y2 < y1) swap(y1,y2);
  39.     if (y4 < y3) swap(y3,y4);
  40.  
  41.     int w = length(x1,x2,x3,x4);
  42.     int h = length(y1,y2,y3,y4);
  43.     int w1 = abs(x2-x1);
  44.     int h1 = abs(y2-y1);
  45.     int w2 = abs(x4-x3);
  46.     int h2 = abs(y4-y3);
  47.  
  48.     cout << h1 * w1 + h2 * w2 - w * h;
  49.  
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top