알고리즘/BOJ

백준 14173번 Square Pasture

꾸준함. 2021. 3. 16. 22:01

문제 링크입니다: 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

그림을 그려보면 쉽게 풀 수 있는 문제였습니다.

 

#include <iostream>
#include <algorithm>
using namespace std;
typedef struct
{
int x1, y1, x2, y2;
}Rectangle;
void getPastureInput(Rectangle &r)
{
cin >> r.x1 >> r.y1 >> r.x2 >> r.y2;
}
int getMaxH(Rectangle r, Rectangle r2)
{
return max(max(r.x2 - r.x1, r2.x2 - r2.x1)
, max(r.x2 - r2.x1, r2.x2 - r.x1));
}
int getMaxR(Rectangle r, Rectangle r2)
{
return max(max(r.y2 - r.y1, r2.y2 - r2.y1)
, max(r.y2 - r2.y1, r2.y2 - r.y1));
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
Rectangle firstPasture, secondPasture;
getPastureInput(firstPasture);
getPastureInput(secondPasture);
int h = getMaxH(firstPasture, secondPasture);
int r = getMaxR(firstPasture, secondPasture);
int side = max(h, r);
int result = side * side;
cout << result << "\n";
return 0;
}
view raw .cpp hosted with ❤ by GitHub

개발환경:Visual Studio 2017

 

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 14470번 전자레인지  (0) 2021.03.17
백준 14264번 정육각형과 삼각형  (0) 2021.03.17
백준 14065번 Gorivo  (0) 2021.03.16
백준 14038번 Tournament Selection  (0) 2021.03.16
백준 13985번 Equality  (0) 2021.03.16