문제 링크입니다: https://www.acmicpc.net/problem/8716
8716번: Pole
W pierwszym wierszu wejścia znajdują się 4 liczby całkowite: x1, y1, x2, y2, oznaczające odpowiednio współrzędną x - ową i y - ową lewego górnego rogu i współrzędną x - ową i y - ową prawego dolnego rogu pierwszego prostokąta. W drug
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
typedef struct | |
{ | |
long long x1, y1; | |
long long x2, y2; | |
} Rectangle; | |
bool isOutOfBound(Rectangle r1, Rectangle r2) | |
{ | |
return (r1.x2 < r2.x1 | |
|| r2.x2 < r1.x1 | |
|| r2.y2 > r1.y1 | |
|| r1.y2 > r2.y1); | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
Rectangle r1, r2; | |
cin >> r1.x1 >> r1.y1 >> r1.x2 >> r1.y2; | |
cin >> r2.x1 >> r2.y1 >> r2.x2 >> r2.y2; | |
if (isOutOfBound(r1, r2)) | |
{ | |
cout << 0 << "\n"; | |
return 0; | |
} | |
long long width = min(r1.x2, r2.x2) - max(r1.x1, r2.x1); | |
long long height = max(r1.y2, r2.y2) - min(r1.y1, r2.y1); | |
long long area = abs(width * height); | |
cout << area << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 8721번 Wykreślanka (0) | 2021.06.27 |
---|---|
백준 8719번 Piłeczka (0) | 2021.06.27 |
백준 8714번 Monety (0) | 2021.06.27 |
백준 8713번 Znak działania (0) | 2021.06.27 |
백준 8678번 Zbiór (0) | 2021.06.27 |