-
[atcoder/335] C - Loong Tracking알고리즘/atcoder 2024. 3. 2. 17:05728x90
https://www.acmicpc.net/problem/3190
3190번: 뱀
'Dummy' 라는 도스게임이 있다. 이 게임에는 뱀이 나와서 기어다니는데, 사과를 먹으면 뱀 길이가 늘어난다. 뱀이 이리저리 기어다니다가 벽 또는 자기자신의 몸과 부딪히면 게임이 끝난다. 게임
www.acmicpc.net
위 문제와 거의 동일하다.
#include <iostream> #include <deque> using namespace std; typedef pair<int, int> pii; deque<pii> dq; int N, Q; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> N >> Q; for (int i = 1; i <= N; ++i) dq.push_back({ i, 0 }); while(Q--){ int q; cin >> q; if (q == 1) { char d; cin >> d; auto head = dq.front(); if (d == 'U') head.second += 1; if (d == 'D') head.second -= 1; if (d == 'L') head.first -= 1; if (d == 'R') head.first += 1; dq.push_front(head); dq.pop_back(); } else { int p; cin >> p; cout << dq[p - 1].first << " " << dq[p - 1].second << "\n"; } } return 0; }
728x90'알고리즘 > atcoder' 카테고리의 다른 글
[atcoder/333] D - Erase Leaves (0) 2024.02.23 [atcoder331] set meal (0) 2024.02.06 [atcoder332] swapping puzzle (1) 2024.02.06 [atcoder331] Sum of Numbers Greater Than Me (0) 2024.02.03 [atcoder/300] counting_ls (0) 2024.01.20