蓝桥杯训练 The 3n+1 problem 模拟
题目链接http://www.dotcpp.com/oj/problem1095.html?sid=760729&lang=1#editor
这个题目只是一道简单的模拟题,为啥我还要贴出来,因为这输出实在是太坑了,留个纪念
ac代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<vector> #include<map> #include<algorithm> using namespace std; const int maxn = 1000000 + 10; int s, t; int a[maxn]; int cycle(int n){ int len = 1; while (n != 1){ if (n % 2 == 0) n /= 2; else n = 3 * n + 1; len++; } return len; } int main() { int tt; ios::sync_with_stdio(false); while (cin >> s >> t){ cout << s << " " << t << ' '; if (s > t) { tt = s, s = t, t = tt; } int res = 0; for (int i = s; i <= t; i++) res = max(res, cycle(i)); cout << res << endl; } return 0; }