본문 바로가기

Algorithm

(C++) - 백준(BOJ) 14173번 : Square Pasture

반응형

https://www.acmicpc.net/problem/14173

 

14173번: Square Pasture

In the example above, the first original rectangle has corners (6,6) and (8,8). The second has corners at (1,8) and (4,9). By drawing a square fence of side length 7 with corners (1,6) and (8,13), the original areas can still be enclosed; moreover, this is

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int x1,x2,y1,y2;
    int a1, a2, b1, b2;
    cin >> x1 >> y1 >> x2 >> y2;
    cin >> a1 >> b1 >> a2 >> b2;
    int ans1 = max(a2, x2) - min(a1,x1);
    int ans2 = max(b2, y2) - min(b1, y1);
    int ans = max(ans1, ans2);
    cout << ans * ans << '\n';
}
cs