BOJ3190: 뱀 작성일 2020-01-27 https://www.acmicpc.net/problem/14889 100문제 풀기는 1월까지로 변경해야 할듯.. 1월동안 100문제 풀기 (8/100) 백트래킹 문제. 걍 시키는 대로 풀면 됨. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#include <bits/stdc++.h> using namespace std; // R, D, L, U const int dx[4] = {0,1,0,-1}; const int dy[4] = {1,0,-1,0}; int N, K, L, board[102][102], dir, tt, x, y; const int BLANK = 0, APPLE = 1, BODY = 2, WALL = 3; char rot[10001]; void turnRight() { dir = (dir+1+4)%4; } void turnLeft() { dir = (dir-1+4)%4; } struct Point{ int x, y; }; int main() { ios::sync_with_stdio(false); cin >> N >> K; for(int i = 0; i < K; i++) { cin >> x >> y; board[x][y] = APPLE; } cin >> L; for(int i = 0; i < L; i++) { char r; cin >> tt >> r; rot[tt] = r; } //Init for(int i = 0; i <= N+1; i++) board[i][0] = board[0][i] = board[N+1][i] = board[i][N+1] = WALL; board[1][1] = BODY; deque<Point> snake; snake.push_back({1,1}); for(tt = 0; ; tt++) { if(rot[tt] == 'L') turnLeft(); else if(rot[tt] == 'D') turnRight(); int nx = snake.front().x + dx[dir]; int ny = snake.front().y + dy[dir]; if(board[nx][ny] == BODY || board[nx][ny] == WALL) break; if(board[nx][ny] == BLANK) { board[snake.back().x][snake.back().y] = BLANK; snake.pop_back(); } board[nx][ny] = BODY; snake.push_front({nx,ny}); } cout << tt+1; }