【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
Sample Output
HINT
Source
【BZOJ】1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏(刷水严重)的更多相关文章
- bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶 ...
- bzoj 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏【模拟】
模拟 #include<iostream> #include<cstdio> using namespace std; int n,ans; int main() { scan ...
- BZOJ 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 幼儿园测试题
本来以为是一道数学题,一顿XJBT导式子,结果就是个幼儿园都会的模拟. Code: #include<bits/stdc++.h> #define ll long long using n ...
- 【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
[算法]贪心&&堆 [题解]反过来看就是合并任意两块木板,花费为木板长度之和. 显然从最小的两块开始合并即可,用堆(优先队列)维护. 经典DP问题石子归并是只能合并相邻两堆石子,所以不 ...
- BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛( LIS )
裸的LIS ----------------------------------------------------------------- #include<cstdio> #incl ...
- 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #in ...
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】
最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 665 Solved: 419 ...
随机推荐
- linux系统中的DNS服务器介绍
http://lq2419.blog.51cto.com/1365130/1172269 DNS:Domain Name Service,linux上的DNS服务是基于一种软件BIND实现的.BIND ...
- Python 创建特殊元组tuple
创建1个元素的tuple (1,) 创建单元素tupletuple和list一样,可以包含 0 个.1个和任意多个元素.包含多个元素的 tuple,前面我们已经创建过了.包含 0 个元素的 tupl ...
- DBMS_METADATA中使用SESSION_TRANSFORM过滤不想获取的DDL
我们一般使用dbms_metadata.get_ddl获取对象的ddl的时候,有时会获取一些其它额外的信息,比如当你想获取表的创建语句的时候,你会得到表的约束信息,这个信息可能是你不想要的,那么就能够 ...
- this详解与面向对象编程
原文链接:http://www.cnblogs.com/kongxy/p/4581223.html JS中的this对象详解 声明:文章转载自上面地址,版权归阿孔所有,这里仅供本人学习笔记使用 t ...
- 解析drupal_render()
drupal_render()函数接收一个结构化的数组作为参数,然后调用theme()输出HTML. function drupal_render(&$elements) { ... ... ...
- ios开发-Object-C可变参数函数
简介 一个可变参数函数是指一个函数拥有不定的参数,即为一个函数可接收多个参数.有时我们会遇到一些算术问题需要用到,比如是计算传入参数的总和,字符串的连接或是其它操作过程,我们在 OC 里也经常使用,最 ...
- [Python]网络爬虫(四):Opener与Handler的介绍和实例应用(转)
在开始后面的内容之前,先来解释一下urllib2中的两个个方法:info and geturl urlopen返回的应答对象response(或者HTTPError实例)有两个很有用的方法info() ...
- RBAC权限设计实例(转)
实现业务系统中的用户权限管理 B/S系统中的权限比C/S中的更显的重要,C/S系统因为具有特殊的客户端,所以访问用户的权限检测可以通过客户端实现或通过客户端+服务器检测实现,而B/S中,浏览器是每一台 ...
- 摘:strings(字符串)简介
之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够.字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是 ...
- jqury插件编写
sae中短信验证码: ; (function($) { $(document).ready(function() { if (parent && parent.location.hre ...