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

【传送门:BZOJ1666


简要题意:

  给出一个数,如果为奇数,则*3+1,否则/2,直到这个数为1

  求数字变化的次数


题解:

  纯模拟,大水题


参考代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int t=0;
    while(n!=1)
    {
        if(n%2==0) n/=2;
        else n=3*n+1;
        t++;
    }
    printf("%d",t);
    return 0;
}

 

posted @ 2018-03-24 11:27  Star_Feel  阅读(218)  评论(0编辑  收藏  举报