标签:nbsp ios long code ret return ace string style
题意:有一个数字,如果是奇数那么*3+1,如果是偶数/2,知道这个数字变成1.问n到m之间需要操作步数最多的数字操作了几步
解:模拟
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <queue> #include <deque> #include <cmath> #include <map> using namespace std; typedef long long ll; const double inf=1e20; const int maxn=1e8+10; const int mod=1e7; ll n,m; int main(){ while(scanf("%lld%lld",&n,&m)!=EOF){ ll nn=n; ll mm=m; if(n>m)swap(n,m); ll num=0; for(int i=n;i<=m;i++){ ll ii=i; ll sum=0; while(ii!=1){ if(ii%2==1)ii=ii*3+1; else ii=ii/2; sum++; } num=max(num,sum); } printf("%lld %lld %lld\n",nn,mm,num+1); } return 0; }
标签:nbsp ios long code ret return ace string style
原文地址:https://www.cnblogs.com/wz-archer/p/12377956.html