题解 | #继续xxx定律#
继续xxx定律
https://www.nowcoder.com/practice/9cc1055241c547269f58fa8b009e335d
#include <iostream> #include <set> #include <stack> using namespace std; const int N = 510; int main() { int n, a; while (cin >> n && n) { // 注意 while 处理多个 case set<int> cover; stack<int> stk; while (n --) { cin >> a; if (cover.count(a)) continue; stk.push(a); while (a != 1) { if (a & 1) a = a * 3 + 1 >> 1; else a >>= 1; cover.insert(a); } } while (stk.size()) { a = stk.top(); stk.pop(); if (!cover.count(a)) cout << a << " "; } puts(""); } return 0; } // 64 位输出请用 printf("%lld")