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): 3691    Accepted Submission(s): 2097

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

Recommend

LL

我是通过找规律得出来的

因为起始的p=1,当2<=n<=9时Stan赢。如果 n 不在2~9之间的话,Ollie要赢,那么n要不大于能得到的最小值 即10<=n<=18

如果n>18呢,那就分析一下

如果S第一次取2,那么可以得到O能选的区间是[4,2*9],可以得到接下来S能赢得区间是[19,4*9]

如果S第一次取3,那么可以得到O能选的区间是[6,3*9],可以得到接下来S能赢得区间是[28,6*9]

如果S第一次取4,那么可以得到O能选的区间是[8,4*9],可以得到接下来S能赢得区间是[37,8*9]

如果S第一次取5,那么可以得到O能选的区间是[10,5*9],可以得到接下来S能赢得区间是[46,10*9]

如果S第一次取6,那么可以得到O能选的区间是[12,6*9],可以得到接下来S能赢得区间是[55,12*9]

如果S第一次取7,那么可以得到O能选的区间是[14,7*9],可以得到接下来S能赢得区间是[64,14*9]

如果S第一次取8,那么可以得到O能选的区间是[16,8*9],可以得到接下来S能赢得区间是[73,16*9]

如果S第一次取9,那么可以得到O能选的区间是[18,9*9],可以得到接下来S能赢得区间是[82,18*9]

那么就能得到S能赢得区间是[19,162]

所以

[2,9] S win

[9+1,2*9] O win

[2*9+1,2*9*9] S win

[2*9*9+1,2*9*9*2] O win

可以看出范围右边交替乘上2和9,左边是上一个区间的 最大值+1

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<stdlib.h>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8     __int64 n;
 9     while(scanf("%I64d",&n)!=EOF)
10     {
11         int i=2,j=9;
12         while(1)
13         {
14             if(i<=n&&n<=j)
15             {
16                 printf("Stan wins.\n");
17                 break;
18             }
19             else
20             {
21                 i=j+1;
22                 j=j*2;
23                 if(i<=n&&n<=j)
24                 {
25                     printf("Ollie wins.\n");
26                     break;
27                 }
28                 i=j+1;
29                 j=j*9;
30             }
31         }
32     }
33     return 0;
34 }

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

时间: 2024-08-05 04:23:07

HDU 1517 A Multiplication Game (博弈&&找规律)的相关文章

HDU 1564 Play a game (博弈&amp;&amp;找规律)

Play a game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1430    Accepted Submission(s): 1168 Problem Description New Year is Coming! ailyanlu is very happy today! and he is playing a chessbo

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 1079 Calendar Game(博弈找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题目大意:给你一个日期(包含年月日),这里我表示成year,month,day,两人轮流操作,每次操作可以将month+1但是,如果下月没有对应的day则只能对day+1(超过该月日数就进入下月一日),或者就day+1.谁最后到达2001.11.4这个日期就是胜者,问先手的人是否能获胜. 解题思路:这个就用上面的P/N分析,一个个月份日期对应的标记上P或N(很快会发现规律只用找每月特定几天),

HDU 4388 Stone Game II {博弈||找规律}

Stone Game II Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 531    Accepted Submission(s): 300 Problem Description Stone Game II comes. It needs two players to play this game. There are some p

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 2147-kiki&#39;s game(博弈/找规律)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others) Total Submission(s): 9174    Accepted Submission(s): 5485 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his

HDU 6154 CaoHaha&#39;s staff 思维 找规律

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6154 题目描述: 围成一个面积不小于S的多边形, 最少需要多少根儿线段, 线段可以为单元格边或者对角线 解题思路: 最大的面积肯定是由根号2为边长的正方形围成了, 那么我们把所有正方形都遍历一遍, 找出S介于N, N+1的那个上界N+1设为max, 因为MAX所围成的多边形面积和MAX-1, MAX-2, MAX-3围成的多边形面积, 找出满足条件的最小的一个即可 代码: #include <io

hdu 2147 kiki&#39;s game(找规律)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total Submission(s): 10656    Accepted Submission(s): 6455 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his

HDU 4349 Xiao Ming&#39;s Hope 找规律

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4349 Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1723    Accepted Submission(s): 1144 Problem Description Xiao Ming likes coun