【hdu 1517】A Multiplication Game
来源:互联网 发布:mac 菜单 快捷键 编辑:程序博客网 时间:2024/04/27 18:39
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5536 Accepted Submission(s): 3151
Problem Description
Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner is who first reaches p >= n.
Input
Each line of input contains one integer number n.
Output
For each line of input output one line either
Stan wins.
or
Ollie wins.
assuming that both of them play perfectly.
Sample Input
162
17
34012226
Sample Output
Stan wins.
Ollie wins.
Stan wins.
【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=1517
【题解】
用sg函数容易推出来小数据的答案;
如下”()”表示先手赢而”{}”表示先手输
一开始l = 2,r = 9;
递推的话
l = r+1;
如果这次是先手赢
则接下来是先手输的态
r = r*2;
如果这次是先手输
则接下来是先手赢的态
r = r*9;
(感性理解:让先手输比较难)
【完整代码】
#include <bits/stdc++.h>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se second#define rei(x) scanf("%d",&x)#define rel(x) scanf("%I64d",&x)typedef pair<int,int> pii;typedef pair<LL,LL> pll;//const int MAXN = x;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);LL n;int main(){ //freopen("F:\\rush.txt","r",stdin); while (~scanf("%I64d",&n)) { int now = 1; LL l = 2,r = 9; while (true) { if (l<=n && n <= r) break; l = r+1; if (now==1) r = r*2; else r = r*9; now ^= 1; } if (now) puts("Stan wins."); else puts("Ollie wins."); } return 0;}
- HDU 1517 A Multiplication Game
- hdu 1517 A Multiplication Game
- hdu 1517 A Multiplication Game
- HDU 1517 - A Multiplication Game
- Hdu 1517 A Multiplication Game
- HDU 1517 A Multiplication Game
- hdu 1517 A Multiplication Game
- A Multiplication Game(hdu 1517)
- hdu 1517 A Multiplication Game
- hdu-1517 A Multiplication Game
- HDU-1517-A Multiplication Game
- HDU 1517:A Multiplication Game
- 【hdu 1517】A Multiplication Game
- 【hdu 1517】A Multiplication Game
- hdu 1517 A Multiplication Game
- hdu 1517 A Multiplication Game
- HDU-1517-A Multiplication Game
- hdu 1517 A Multiplication Game
- magento如何设置产品列表页面的产品数量
- iOS抽屉效果
- Oracle的列转行函数:LISTAGG()
- 可以左右滑动查看内容的文本框
- Android Studio 生成Release版,报Warning的解决办法
- 【hdu 1517】A Multiplication Game
- python 学习2:生成器,迭代器,装饰器
- NOSQL数据库浅谈(一):MemCache解读
- typedef用法(转载记录)
- jsp、struts、spring、mybatis实现前端页面功能模块化拆分
- Android中ImageLoader的用法
- Protocol buffer数据传递
- 平衡二叉树总结三:treap树(树堆)
- 解决json序列化有多对一和多对多关系的对象时造成死循环的问题