상자가 3개로 고정되어있으므로 완전탐색을 쓰기로 했다.
바뀌는 경우의 수는
1. 옆으로 회전시
2. 상자위치 변경
3. 상자 구조 변경
for (int j = 0; j < 3; j++)
{
cin >> a[j].first >> a[j].second;
}
for (size_t j = 0; j < 3; j++)
{
a[j + 3].first = a[j].second;
a[j + 3].second = a[j].first;
}
이렇게 옆으로 회전하는 경우를 계산했다.
for (int q = 0; q < 6; q++)
{
for (int w = 0; w < 6; w++)
{
for (int e = 0; e < 6; e++)
{
if (q % 3 == w % 3 || w % 3 == e % 3 || e % 3 == q % 3) {
continue;
}
반복문을 3개쓰고 if문으로 안되는 경우를 걸렀다. 이렇게 q w e로 3가지의 상자를 표현했다.
void second(int q, int w, int e) {
int width = max(a[q].first, a[w].first + a[e].first);
int height = a[q].second + max(a[w].second, a[e].second);
ans = min(ans, width * height);
}
void three(int q, int w, int e) {
int width = max(a[q].first, a[w].first);
width = max(width, a[e].first);
int height = a[q].second + a[w].second + a[e].second;
ans = min(ans, width * height);
}
상자가 1+2로 2층으로 놓인경우와 3+0으로 3층, 일자로 놓인경우를 표현했다.