Deep Learning study
백준 3190문제 본문
반응형
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define FOR(i,a,b) for(int i=a ; i<b ; i++)
int N,K,L,sec, board[101][101];
int a,b,cur_dir;
queue<pair<int,int>> snake;
int gox[4] = {0,1,0,-1};
int goy[4] = {1,0,-1,0};
bool check(){
return a < N && a >=0 && b < N && b >=0 && board[a][b] != 2;
}
bool move(int nxt){
a += gox[cur_dir%4], b+= goy[cur_dir%4];
if(!check()) return false;
snake.push(make_pair(a,b));
if(board[a][b] == 0){
pair<int,int> tmp = snake.front();
board[tmp.x][tmp.y] = 0;
snake.pop();
}
board[a][b] = 2;
if(nxt == 'L') cur_dir += 3;
else if(nxt == 'D') cur_dir++;
return true;
}
int main(){
cin >> N >> K;
FOR(i,0,K){
int m,n; cin >> m >> n;
board[m-1][n-1] = 1;
}
cin >> L;
queue<pair<int,char>> dir;
FOR(i,0,L){
int s;
char c; cin >> s >> c;
dir.push(pair<int,char>(s,c));
}
pair<int,char> p = dir.front();
dir.pop();
cur_dir = 0;
board[0][0] = 2;
snake.push({0,0});
bool flag;
while(true){
sec++;
if(p.x == sec){
flag = move((int)p.y);
p = dir.front(), dir.pop();
}else flag = move(0);
if(!flag) break;
}
cout << sec << '\n';
return 0;
}
백준 3190 문제 풀이입니다.
반응형
'백준 문제 코드' 카테고리의 다른 글
백준 14503문제 (0) | 2019.12.18 |
---|---|
백준 14889문제 (0) | 2019.12.17 |
백준 14500문제 (0) | 2019.12.16 |
백준 14499문제 (0) | 2019.12.12 |
백준 14501문제 (0) | 2019.12.10 |
Comments