Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- django
- programmers
- 코딩테스트
- 시뮬레이션
- CSV
- Algorithm
- BFS
- SWEA
- 알고리즘
- 알고리듬
- JavaScript
- spring boot
- DFS
- Bruth Force
- Data Structure
- gpdb
- Python
- Vue.js
- hash table
- SQL
- Back tracking
- Priority Queue
- 구현
- aws
- GitHub
- 모의SW역량테스트
- Linked list
- boj
- Trie
- 코테
Archives
- Today
- Total
hotamul의 개발 이야기
[Algorithm][C++] JUNGOL 4193: swat. 애벌레 키우기1 본문
myt-algorithm-practice/Samsung SW Certi Adv
[Algorithm][C++] JUNGOL 4193: swat. 애벌레 키우기1
hotamul 2021. 10. 28. 20:53url: http://jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=3543
JUNGOL
www.jungol.co.kr
BOJ 뱀 문제와 거의 같은 문제. (https://hotamul.tistory.com/17)
코드
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <deque>
using namespace std;
int N, M, D;
bool map[100][100];
bool body[100][100];
int DIR[10000];
const int dr[] = { -1,0,1,0 };
const int dc[] = { 0,1,0,-1 };
struct POS { int r, c; };
deque<POS> worm;
int solve() {
int time = -1;
int dir = 1;
body[0][0] = true;
worm.push_front({ 0,0 });
while (1) {
++time;
if (DIR[time]) {
dir = (dir + DIR[time]) % 4;
}
POS head = worm.front();
int nr = head.r + dr[dir];
int nc = head.c + dc[dir];
if (nr < 0 || nr >= N || nc < 0 || nc >= N || body[nr][nc]) {
break;
}
if (!map[nr][nc]) {
POS tail = worm.back();
body[tail.r][tail.c] = false;
worm.pop_back();
}
else {
map[nr][nc] = 0;
}
body[nr][nc] = true;
worm.push_front({ nr,nc });
}
return time + 1;
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
int r, c;
scanf("%d %d", &r, &c);
--r, --c;
map[r][c] = true;
}
scanf("%d", &D);
for (int i = 0; i < D; i++) {
int t;
char c;
scanf("%d %c", &t, &c);
if (c == 'R') {
DIR[t] = 1;
}
else {
DIR[t] = 3;
}
}
int ret = solve();
printf("%d", ret);
return 0;
}
'myt-algorithm-practice > Samsung SW Certi Adv' 카테고리의 다른 글
[Algorithm][C++] JUNGOL 4198: swat. 산불 (0) | 2021.11.01 |
---|---|
[Algorithm][C++] JUNGOL 4197: swat. 연습실 (0) | 2021.10.28 |
[Algorithm][C++] SWEA 1249. [S/W 문제해결 응용] 보급로 문제 (0) | 2021.10.27 |
[Algorithm][C++] BOJ 12100 2048(Easy) (0) | 2021.10.24 |
[Algorithm][C++] BOJ 13460 구슬 탈출 2 (0) | 2021.10.24 |
Comments