bzoj1666[Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏*

bzoj1666[Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

题意:

一个数为偶数就让它/2,为奇数就让它*3+1,问多少步可以让它变成1。n≤1000000

题解:

模拟。

代码:

1 #include <cstdio>
2 int main(){
3     int n; scanf("%d",&n); int ans=0;
4     while(n!=1){if(n&1)n=n*3+1;else n>>=1; ans++;}
5     printf("%d",ans); return 0;
6 }

 

20160727

posted @ 2016-07-27 23:16  YuanZiming  阅读(152)  评论(0编辑  收藏  举报