2477 참외밭
2019. 4. 21. 22:01ㆍ알고리즘/백준
육각형의 참외밭의 넓이를 구하는 문제다
기존 사각형에서 빠진 사각형을 빼면 넓이를 구할 수 있다
사각형은 방향이 서로 ㄱ자의 방향을 이루면서 나오기 때문에 성질을 이용할 수 있다
문제: https://www.acmicpc.net/problem/2477
깃허브주소: https://github.com/surinoel/boj/blob/master/2447.cpp
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> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int k; cin >> k; | |
vector<pair<int, int>> shape(6); | |
for (int i = 0; i < 6; i++) { | |
cin >> shape[i].first >> shape[i].second; | |
} | |
int area = -1; | |
int ans = -1; | |
for (int i = 0; i < 6; i++) { | |
int artmp = shape[i].second * shape[(i + 1) % 6].second; | |
if (area == -1 || artmp > area) { | |
area = artmp; | |
ans = area - shape[(i + 3) % 6].second * shape[(i + 4) % 6].second; | |
} | |
} | |
cout << ans * k << '\n'; | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
1024 수열의 합 (0) | 2019.04.22 |
---|---|
1015 수열 정렬 (0) | 2019.04.21 |
16951 블록 놀이 (0) | 2019.04.21 |
1316 그룹 단어 체커 (0) | 2019.04.20 |
16943 숫자 재배치 (0) | 2019.04.20 |