티스토리 뷰

알고리즘/SWEA

[SWEA 5650] 핀볼 게임

히더 2018. 9. 19. 15:03

SW Expert Academy :: SWEA :: 5650 :: 핀볼게임


출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRF8s6ezEDFAUo


#include <bits/stdc++.h>

using namespace std;


struct S { int y, x, d; };

int T, N, tc, ans, A[102][102], dy[] = { -1,0,1,0 }, dx[] = { 0,1,0,-1 },

C[6][4] = { {},{2,3,1,0},{1,3,0,2},{3,2,0,1},{2,0,3,1},{2,3,0,1} }, D[5][5];


void G() {

for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) {

if (!A[i][j]) {

S n = { i,j }, z = n;

for (int dr = 0; dr < 4; dr++) {

int r = 0; n = z; n.d = dr;

while (1) {

n.y += dy[n.d], n.x += dx[n.d]; int p = A[n.y][n.x];

if (!p && !r) break;

if (A[n.y][n.x] < 0 || (z.y == n.y&&z.x == n.x)) break;

if (p) {

if (p < 6) n.d = C[p][n.d], r++;

else {

if (n.y == D[p % 6][1] && n.x == D[p % 6][2]) { n.y = D[p % 6][3], n.x = D[p % 6][4]; }

else { n.y = D[p % 6][1], n.x = D[p % 6][2]; }

}

}

} ans = max(ans, r);

}

}

}

}


int main() {

ios::sync_with_stdio(0); cin.tie(0); cin >> T;

while (T--) {

cin >> N; ans = 0; memset(D, 0, sizeof(D));

for (int i = 0; i < N + 2; i++) A[i][0] = A[0][i] = A[N + 1][i] = A[i][N + 1] = 5;

for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) {

cin >> A[i][j];

if (A[i][j] > 5) {

int l = A[i][j] % 6, k = D[l][0];

D[l][++k] = i, D[l][++k] = j; D[l][0] = k;

}

}

G();

cout << "#" << ++tc << " " << ans << '\n';

}

return 0;

}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 5644] 무선 충전  (0) 2018.09.21
[SWEA 5648] 원자 소멸 시뮬레이션  (0) 2018.09.20
[SWEA 5521] 상원이의 생일파티  (0) 2018.09.07
[SWEA 5436] 동욱이의 조판하기  (0) 2018.08.29
[SWEA 5432] 쇠막대기 자르기  (0) 2018.08.29
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함