Muscardinus

낚시왕 본문

카테고리 없음

낚시왕

Muscardinus 2020. 9. 3. 13:33
728x90

www.acmicpc.net/problem/17143

 

17143번: 낚시왕

낚시왕이 상어 낚시를 하는 곳은 크기가 R×C인 격자판으로 나타낼 수 있다. 격자판의 각 칸은 (r, c)로 나타낼 수 있다. r은 행, c는 열이고, (R, C)는 아래 그림에서 가장 오른쪽 아래에 있는 칸이다.

www.acmicpc.net

#include <iostream>

using namespace std;

struct CELL {
	int s, d, z;
};

CELL map[2][101][101];
int r, c, m;
int cur = 0;

int fishing(int cur, int pos) {
	int size = 0;
	for (int y = 0; y < r; y++) {
		if (map[cur][y][pos].z) {
			size = map[cur][y][pos].z;
			map[cur][y][pos].s = 0;
			map[cur][y][pos].d = 0;
			map[cur][y][pos].z = 0;
			break;
		}
	}
	return size;
}

void move(int cur) {
	int next = (cur + 1) % 2;
	for (int y = 0; y < r; y++) {
		for (int x = 0; x < c; x++) {
			map[next][y][x].s = 0;
			map[next][y][x].d = 0;
			map[next][y][x].z = 0;
		}
	}
	for (int y = 0; y < r; y++) {
		for (int x = 0; x < c; x++) {
			if (map[cur][y][x].z) {
				if (map[cur][y][x].d == 1) {
					int ny = ((r - 1) * 2 - y) + map[cur][y][x].s;
					ny = (ny % ((r - 1) * 2));
					int nd = 2;
					if (ny >= (r - 1)) {
						ny = ((r - 1) * 2) - ny;
						nd = 1;
					}
					if (map[next][ny][x].z < map[cur][y][x].z) {
						map[next][ny][x].s = map[cur][y][x].s;
						map[next][ny][x].d = nd;
						map[next][ny][x].z = map[cur][y][x].z;
					}
				}
				else if (map[cur][y][x].d == 2) {
					int ny = y + map[cur][y][x].s;
					ny = (ny % ((r - 1) * 2));
					int nd = 2;
					if (ny >= (r - 1)) {
						ny = ((r - 1) * 2) - ny;
						nd = 1;
					}
					if (map[next][ny][x].z < map[cur][y][x].z) {
						map[next][ny][x].s = map[cur][y][x].s;
						map[next][ny][x].d = nd;
						map[next][ny][x].z = map[cur][y][x].z;
					}
				}
				else if (map[cur][y][x].d == 3) {
					int nx = x + map[cur][y][x].s;
					nx = (nx % ((c - 1) * 2));
					int nd = 3;
					if (nx >= (c - 1)) {
						nx = ((c - 1) * 2) - nx;
						nd = 4;
					}
					if (map[next][y][nx].z < map[cur][y][x].z) {
						map[next][y][nx].s = map[cur][y][x].s;
						map[next][y][nx].d = nd;
						map[next][y][nx].z = map[cur][y][x].z;
					}
				}
				else {
					int nx = ((c - 1) * 2 - x) + map[cur][y][x].s;
					nx = (nx % ((c - 1) * 2));
					int nd = 3;
					if (nx >= c - 1) {
						nx = (c - 1) * 2 - nx;
						nd = 4;
					}
					if (map[next][y][nx].z < map[cur][y][x].z) {
						map[next][y][nx].s = map[cur][y][x].s;
						map[next][y][nx].d = nd;
						map[next][y][nx].z = map[cur][y][x].z;
					}
				}
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> r >> c >> m;
	int answer = 0;
	int y, x;
	for (int i = 0; i < m; i++) {
		cin >> y >> x;
		y--; x--;
		cin >> map[cur][y][x].s >> map[cur][y][x].d >> map[cur][y][x].z;
	}
	for (int pos = 0; pos < c; pos++) {
		answer += fishing(cur, pos);
		move(cur);
		cur = (cur + 1) % 2;
	}
	cout << answer << "\n";
	return 0;
}
728x90
Comments