https://www.acmicpc.net/problem/20061
#include <iostream>
using namespace std;
int n;
int red[4][4];
int blue[4][6];
int green[6][4];
int answer = 0;
pair<int,int> MoveToBlue(int i, int j) {
pair<int, int> ans = make_pair(-1,-1);
for (int k = 0; k < 6; k++) {
if (blue[i][k] == 1) {
ans = make_pair(i, k - 1);
break;
}
}
if (ans == make_pair(-1, -1)) {
ans = make_pair(i, 5);
}
return ans;
}
pair<int,int> MoveToGreen(int i, int j) {
pair<int, int> ans = make_pair(-1,-1);
for (int k = 0; k < 6; k++) {
if (green[k][j] == 1) {
ans = make_pair(k - 1, j);
break;
}
}
if (ans == make_pair(-1, -1)) {
ans = make_pair(5, j);
}
return ans;
}
void DeleteBlock() {
for (int j = 0; j < 6; j++) {
int count = 0;
for (int i = 0; i < 4; i++) {
if (blue[i][j] == 1) count++;
}
if (count == 4) {
answer += 1;
for (int i = j - 1; i >= 0; i--) {
for (int k = 0; k < 4; k++) {
blue[k][i+1] = blue[k][i];
}
}
}
}
for (int i = 0; i < 6; i++) {
int count = 0;
for (int j = 0; j < 4; j++) {
if (green[i][j] == 1) count++;
}
if (count == 4) {
answer += 1;
for (int k = i - 1; k >= 0; k--) {
for (int j = 0; j < 4; j++) {
green[k + 1][j] = green[k][j];
}
}
}
}
}
void DeleteSmooth() {
int count = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
if (green[i][j] == 1) {
count += 1;
break;
}
}
}
for (int i = 5; i >= 2; i--) {
for (int j = 0; j < 4; j++) {
green[i][j] = green[i-count][j];
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
green[i][j] = 0;
}
}
count = 0;
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 4; i++) {
if (blue[i][j] == 1) {
count += 1;
break;
}
}
}
for (int j = 5; j >= 2; j--) {
for (int i = 0; i < 4; i++) {
blue[i][j] = blue[i][j - count];
}
}
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 4; i++) {
blue[i][j] = 0;
}
}
}
int main(void) {
cin >> n;
for (int k = 0; k < n; k++) {
int t, i, j;
cin >> t >> i >> j;
if (t == 1) {
pair<int, int> tmp = MoveToBlue(i, j);
blue[tmp.first][tmp.second] = 1;
tmp = MoveToGreen(i, j);
green[tmp.first][tmp.second] = 1;
}
else if (t == 2) { pair<int,int> tmp = MoveToBlue(i, j + 1);
blue[tmp.first][tmp.second] = 1;
blue[tmp.first][tmp.second - 1] = 1;
tmp = MoveToGreen(i, j);
green[tmp.first][tmp.second] = 1;
pair<int,int> tmp2 = MoveToGreen(i, j + 1);
green[tmp2.first][tmp2.second] = 1;
if (tmp.first < tmp2.first) {
green[tmp2.first][tmp2.second] = 0;
green[tmp.first][tmp.second + 1] = 1;
}
else if (tmp.first > tmp2.first) {
green[tmp.first][tmp.second] = 0;
green[tmp2.first][tmp2.second - 1] = 1;
}
}
else if (t == 3) {
pair<int, int> tmp = MoveToGreen(i + 1, j);
green[tmp.first][tmp.second] = 1;
green[tmp.first - 1][tmp.second] = 1;
tmp = MoveToBlue(i, j);
blue[tmp.first][tmp.second] = 1;
pair<int, int> tmp2 = MoveToBlue(i + 1, j);
blue[tmp2.first][tmp2.second] = 1;
if (tmp.second > tmp2.second) {
blue[tmp.first][tmp.second] = 0;
blue[tmp2.first-1][tmp2.second] = 1;
}
else if (tmp.second < tmp2.second) {
blue[tmp2.first][tmp2.second] = 0;
blue[tmp.first+1][tmp.second] = 1;
}
}
DeleteBlock();
DeleteSmooth();
}
cout << answer << endl;
int answer = 0;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 4; j++) {
if (green[i][j] == 1) answer += 1;
if (blue[j][i] == 1) answer += 1;
}
}
cout << answer << endl;
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
상어 초등학교 C++ (0) | 2021.09.18 |
---|---|
마법사 상어와 블리자드 C++ (0) | 2021.09.18 |
백준 주사위 윷놀이 C++ (0) | 2021.07.21 |
마법사 상어와 비바라기 (0) | 2021.06.28 |
상어 중학교 (0) | 2021.06.28 |