Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cmath>
- #include <vector>
- #define ll long long
- #define even(a) a%2==0?0:1
- void speed() {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- std::cout.tie(nullptr);
- }
- using namespace std;
- int length(int l1, int r1, int l2, int r2) {
- int l = max(l1, l2);
- int r = min(r1, r2);
- if (r < l) return 0; // пересечения нет
- else return r - l;
- return 0;
- }
- int main() {
- speed();
- int x1,x2,x3,x4;
- int y1,y2,y3,y4;
- cin >> x1 >> y1 >> x2 >> y2;
- cin >> x3 >> y3 >> x4 >> y4;
- if (x2 < x1) swap(x1,x2);
- if (x4 < x3) swap(x3,x4);
- if (y2 < y1) swap(y1,y2);
- if (y4 < y3) swap(y3,y4);
- int w = length(x1,x2,x3,x4);
- int h = length(y1,y2,y3,y4);
- int w1 = abs(x2-x1);
- int h1 = abs(y2-y1);
- int w2 = abs(x4-x3);
- int h2 = abs(y4-y3);
- cout << h1 * w1 + h2 * w2 - w * h;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement