BZOJ 1666 USACO 2006 Oct. 奶牛的数字游戏

 

  直接模拟2333

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 int n,ans;
 5 void read(int &k){
 6     k=0; int f=1; char c=getchar();
 7     while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
 8     while ('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
 9     k*=f;
10 }
11 int main(){
12     read(n);
13     while (n!=1){
14         if (n&1) n=n*3+1;
15         else n=n/2;
16         ans++;
17     }
18     printf("%d",ans);
19 }
View Code

 

posted @ 2017-10-19 10:13  Driver_Lao  阅读(169)  评论(0编辑  收藏  举报