2015-12-11から1日間の記事一覧
#include <iostream> #include <stack> int main() { int n; std::cin >> n; std::stack<int> s[3]; for (int i = n; i > 0; --i) { s[0].push(i); } int mpos = 0; while (!s[0].empty() || !s[1].empty()) { s[(mpos + 1 + (n % 2)) % 3].push(s[mpos].top()); s[mpos].pop(); mp</int></stack></iostream>…