zoukankan      html  css  js  c++  java
  • bzoj1666[Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    Description

    奶牛们又在玩一种无聊的数字游戏。输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果。在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000)。此时奶牛们的分数均为0。如果N是奇数,那么奶牛就会把它乘以3后再加1。如果N是偶数,那么这个数就会被除以2。数字每变动一次,这头奶牛就得到1分。当N的值等于1时,游戏结束,此时的分数就是这头奶牛在这局游戏中的最终得分。 以下是N的初始值为5时,一局游戏的完整过程: N 操作后所得数 注释 总分 5 16 3*5+1 1 16 8 16/2 2 8 4 8/2 3 4 2 4/2 4 2 1 2/2 5 这头奶牛的最终得分是5。

    Input

    * 第1行: 一个正整数,N

    Output

    * 第1行: 输出一个正整数N,即奶牛在这局游戏中的最终得分

    Sample Input

    112

    Sample Output

    20

    。。。完全不能理解为什么这是usaco金组题……完全是模拟嘛

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x*=10;x+=ch-'0';ch=getchar();}
        return x*f;
    }
    int n,rep;
    int main()
    {
        n=read();
    while (n!=1) 
        { 
          rep++; 
          if (n%2==0) n=n/2; 
          else n=n*3+1; 
        }
    cout<<rep;
    }
    

      

    ——by zhber,转载请注明来源
  • 相关阅读:
    idea
    C#
    mysql
    .net5
    .net5
    .net5
    .net5
    .net5
    .net5
    .net5
  • 原文地址:https://www.cnblogs.com/zhber/p/4036113.html
Copyright © 2011-2022 走看看