PAT 乙级 1005 继续(3n+1)猜想
题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805320306507776
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n] = {}; for (int i = 0; i < n; i++) cin >> a[i]; map<int, bool> vis; for (int i = 0; i < n; i++) { int x = a[i]; while (x != 1) { if (x & 1) x = (3 * x + 1) / 2; else x = x / 2; vis[x] = true; } } set<int> ans; for (int i = 0; i < n; i++) if (!vis[a[i]]) ans.insert(a[i]); for (auto it = ans.rbegin(); it != ans.rend(); it++) cout << *it << " \n"[it == --ans.rend()]; }

浙公网安备 33010602011771号