bzoj1666[Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
2014-06-02 23:28
519 查看
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行: 一个正整数,NOutput
* 第1行: 输出一个正整数N,即奶牛在这局游戏中的最终得分Sample Input
112Sample 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; }
相关文章推荐
- 【BZOJ】1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏(刷水严重)
- BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- bzoj 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- BZOJ 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- bzoj1666[Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- 【bzoj1666】 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- 【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- bzoj 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏【模拟】
- 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- BZOJ_P1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏(hhhhhh)
- 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 记忆化搜索
- [BZOJ3404][Usaco2009 Open]Cow Digit Game又见数字游戏
- BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
- 【BZOJ】【3404】【USACO2009 Open】Cow Digit Game又见数字游戏
- 【博弈论】【SG函数】bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏
- bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏
- [bzoj3404] [Usaco2009 Open]Cow Digit Game又见数字游戏