【BZOJ】1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏(刷水严重)

http://www.lydsy.com/JudgeOnline/problem.php?id=1666

这种我就不说了。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }

int main() {
	int n=getint(), ans=0;
	while(n!=1) {
		if(n&1) n=n*3+1;
		else n>>=1;
		++ans;
	}
	print(ans);
	return 0;
}

 

 


 

 

Description

奶 牛们又在玩一种无聊的数字游戏。输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果。在游戏的开始,每头牛都会得到一个数N(1<=N& lt;=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

HINT

Source

posted @ 2014-09-02 17:40  iwtwiioi  阅读(368)  评论(0编辑  收藏  举报