C - Loong Tracking
C - Loong Tracking
https://atcoder.jp/contests/abc335/tasks/abc335_c
思路
贪吃蛇,头部不断更新, 原来的头部会变成颈部,颈部变成胸膛,..., 原来的尾部删除。
采用双端队列,
头部 根据 头部做更新
尾部删除。
Code
https://atcoder.jp/contests/abc335/submissions/49143475
struct NODE{ int x; int y; }; deque<struct NODE> dq; int n,q; int main() { cin >> n; cin >> q; for(int i=1; i<=n; i++){ struct NODE nd; nd.x = i; nd.y = 0; dq.push_back(nd); } for(int i=0; i<q; i++){ int action; cin >> action; if (action == 1){ char c; cin >> c; struct NODE f; f = dq.front(); if (c == 'U'){ f.y++; } else if (c == 'D') { f.y--; } else if (c == 'L') { f.x--; } else if (c == 'R') { f.x++; } else { // no other branch should happen } dq.push_front(f); dq.pop_back(); } else if (action == 2){ int p; cin >> p; cout << dq[p-1].x << " " << dq[p-1].y << endl; } } return 0; }
出处:http://www.cnblogs.com/lightsong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。