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的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. Core Animation 文档翻译—附录A(Layer样貌相关属性动画)

    前言   在渲染过程中,核心动画获取Layer的各种属性并以特定的顺序渲染他们.这个顺序决定了Layer的最终的样貌.本节将会阐述通过设置不同的Layer样貌相关属性对应产生的渲染结果. 注意:Mac ...

  2. 24.C语言最全排序方法小结(不断更新)

    希尔排序: 该方法的基本思想是:先将整个待排元素序列切割成若干个子序列(由相隔某个“增量”的元素组成的)分别进行直接插入排序,然后依次缩减增量再进行排序,待整个序列中的元素基本有序(增量足够小)时,再 ...

  3. 学习笔记(二):javascript之dom操作

    一.document.getElementById()    根据Id获取元素节点 <div id="div1"> <p id="p1"> ...

  4. 【CS Round #43 C】Rectangle Partition

    [链接]点击打开链接 [题意] 有一辆火车,它的长度为L,然后假设这辆车现在随机可能地出现在0..D之间,然后假设它已经耗光了油. 问你它需要走的期望距离是多少. 这里要走的距离指的是车里最近的加油站 ...

  5. 洛谷——P1548 棋盘问题

    https://www.luogu.org/problem/show?pid=1548#sub 题目描述 设有一个N*M方格的棋盘(l<=N<=100,1<=M<=100)(3 ...

  6. amazeui学习笔记--css(常用组件8)--列表list

    amazeui学习笔记--css(常用组件8)--列表list 一.总结 1.链接列表:就是多个链接在一起组成的列表, 使用 <ul> 结构嵌套链接列表,添加 .am-list.还是ui包 ...

  7. 扩展的方法:es6 安装模块builder

    https://github.com/es-shims/es5-shim/ Image.png 检测浏览器可支持es5,不支持就扩展,做兼容: 扩展的方法: Image.png 取所有对象的键值: o ...

  8. 判断Bigdecimal类型是否等于0的方法

    1.我之前用来判断Bigdecimal类型是否等于0的方法 b.equals(BigDecimal.ZERO); 用equals方法和BigDecimal.ZERO进行比较. 2.上面方法存在的问题 ...

  9. Oracle数据库(三)

    专题一:oracle查询 1.where查询 查询部门编号是1的部门信息 ; 查询姓名是kw的员工,字符串使用‘’,内容大小写敏感 select *from emp where name='kw' 查 ...

  10. 使用DNSCrypt解决Dropbox污染问题

     作者:半点闲 时间:2014-6-27 18:27 博客:blog.csdn.net/cg_i 邮箱:b_dx@sohu.com 背景知识:防火长城(GFW) keyword:DNSCrypt ...