hdu 1517 A Multiplication Game 段sg

A Multiplication Game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3832    Accepted Submission(s): 2183

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.

Source

University of Waterloo Local Contest 2001.09.22

没有想到应该这样分析.....

打了sg表...1 肯定必败 (2,9)必胜 (10,18)必败,(19,36)必胜...总之就是((2*9)^i+1,(2*9)^i*9)必败

#include <cstdio>
#include <cstring>
using namespace std;
long long n;
int main(){
    while(scanf("%I64d",&n)!=EOF){
        long long tn=1;
        bool fl=false;
        while(n>tn){
            tn*=9;fl=true;
            if(n<=tn)break;
            tn*=2;fl=false;
        }
        if(fl)printf("Stan wins.\n");
        else printf("Ollie wins.\n");
    }
    return  0;
}

  

时间: 2024-10-17 10:59:37

hdu 1517 A Multiplication Game 段sg的相关文章

HDU 1517 A Multiplication Game (博弈-求sg)

A Multiplication Game 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

HDU 1517 A Multiplication Game (博弈&amp;&amp;找规律)

A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3691    Accepted Submission(s): 2097 Problem Description Stan and Ollie play the game of multiplication by multiplying an in

HDU 1517 A Multiplication Game(博弈论)

题目地址:HDU 1517 NP状态转换. 可以把题目的向上乘变成向下除.这样1是终结状态,设1的时候为必败点. 根据所有能一步到达必败点的点是必胜点,所以[x,x*9]必胜点:根据只能到达必胜点的点是必败点,所以[x*9+1,x*9*2]是必败点. 然后求解. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdli

hdu 1517 A Multiplication Game(必胜态,必败态)

A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5833    Accepted Submission(s): 3303 Problem Description Stan and Ollie play the game of multiplication by multiplying an in

HDU 1517 A Multiplication Game 博弈

A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6202    Accepted Submission(s): 3532 Problem Description Stan and Ollie play the game of multiplication by multiplying an in

HDU 1517: kiki&#39;s game

/** * @link http://acm.hdu.edu.cn/showproblem.php?pid=1517 * @author Sycamore * @date Aug, 21 */// Suppose that their exists a direction(vertically or horizontally) in which// the steps remaining to arrive at the destination (n-1 or m-1) is even, as

HDU 4902 Matrix multiplication

点击打开链接 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2113    Accepted Submission(s): 956 Problem Description Given two matrices A and B of size n×n, find the product o

HDU 4920 Matrix multiplication(矩阵相乘)

各种TEL,233啊.没想到是处理掉0的情况就可以过啊.一直以为会有极端数据.没想到竟然是这样的啊..在网上看到了一个AC的神奇的代码,经典的矩阵乘法,只不过把最内层的枚举,移到外面就过了啊...有点不理解啊,复杂度不是一样的吗.. Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 640 

hdu 4920 Matrix multiplication(矩阵乘法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 989    Accepted Submission(s): 396 Problem Description Given two matr