A Multiplication Game

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

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.
 
解题思路:
由于每次都是从p=1开始的,所以只要判断每个游戏中1为必败点还是必胜点即可。(以下各式 / 均为取上整)
依照上面所提到的算法,将终结位置,即[n,无穷]标记为必败点;
然后将所有一步能到达此必败段的点标记为必胜点,即[n/9,n-1]为必胜点;
然后将只能到达必胜点的点标记为必败点,即[n/9/2,n/9-1]为必败点;
重复上面2个步骤,直至可以确定1是必胜点还是必败点。
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
using namespace std; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int x;
for(x=;n>;x++)
{
if(x&)
n=ceil(n*1.0/);
else
n=ceil(n*1.0/);
}
if(x&)
printf("Stan wins.\n");
else
printf("Ollie wins.\n");
}
return ;
}

HDU_1517_博弈(巧妙规律)的更多相关文章

  1. 51nod_1831: 小C的游戏(Bash博弈 找规律)

    题目链接 此类博弈不需要考虑sg函数,只需要确定必胜态和必败态,解题思路一般为打败先打表找规律,而后找规律给出统一的公式.打表方式:给定初始条件(此题中为ok[0]=ok[1]=0),然后从低到高枚举 ...

  2. Gym - 101775L SOS 博弈 找规律

    题目:https://cn.vjudge.net/problem/Gym-101775L PS:训练赛中被这道题折磨的不轻,和队友反复推必胜态与必败态试图推导出公式或者规律,然后推的心态逐渐失控,,, ...

  3. HDU-1847 Good Luck in CET-4 Everybody! (博弈+找规律)

    大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此.当然,作为在考场浸润了十几载的当代大学生,Kiki和Cici更懂得考 ...

  4. 51nod 1831: 小C的游戏(Bash博弈 找规律)

    题目链接 此类博弈不需要考虑sg函数,只需要确定必胜态和必败态,解题思路一般为打败先打表找规律,而后找规律给出统一的公式.打表方式:给定初始条件(此题中为ok[0]=ok[1]=0),然后从低到高枚举 ...

  5. HDU 1079 Calendar Game(博弈找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题目大意:给你一个日期(包含年月日),这里我表示成year,month,day,两人轮流操作,每 ...

  6. HDU 1847 (博弈 找规律) Good Luck in CET-4 Everybody!

    为了提高题解质量还是简单证明一下:3的倍数是必败状态. 如果n % 3 = 1,那么拿走1个石子:如果n % 3 = 2,那么拿走两个石子,都将转移到3的倍数的状态.所以每个必胜状态都有一个后继是必败 ...

  7. HDU 2897 (博弈 找规律) 邂逅明下

    根据博弈论的两条规则: 一个状态是必胜状态当且仅当有一个后继是必败状态 一个状态是必败状态当且仅当所有后继都是必胜状态 然后很容易发现从1开始,前p个状态是必败状态,后面q个状态是必胜状态,然后循环往 ...

  8. hdu 1564 Play a game(博弈找规律)

    题目:一个n*n的棋盘,每一次从角落出发,每次移动到相邻的,而且没有经过的格子上. 谁不能操作了谁输. 思路:看起来就跟奇偶性有关 走两步就知道了 #include <iostream> ...

  9. POJ 1740 A New Stone Game(多堆博弈找规律)

    传送门 //有n堆,AB轮流从n堆的一堆中移任意个,可以扔掉,也可以移给其他堆中的一堆 //最先移完的胜 //如果n堆中两两堆数目相等,那肯定是B胜 //但只要有非两两相同的,如xyz,A先, //A ...

随机推荐

  1. const关键字作用

    const int a; int const a; const int *a; int * const a; int const * a const; /******/ 前两个的作用是一样,a是一个常 ...

  2. 洛谷——P2639 [USACO09OCT]Bessie的体重问题Bessie's We…

    https://www.luogu.org/problem/show?pid=2639 题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉. ...

  3. Codeforces Round #305 (Div. 2) C题 (数论)

    C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. [Jest] Write data driven tests in Jest with test.each

    Often, we end up creating multiple unit tests for the same unit of code to make sure it behaves as e ...

  5. Java UDP通信简单实现

    1.Java实现方式 1)server端 /** * UDPserver端 * */ public class UdpServer { // 定义一些常量 private final intMAX_L ...

  6. OllyDbg 使用笔记 (七)

    OllyDbg 使用笔记 (七) 參考 书:<加密与解密> 视频:小甲鱼 解密系列 视频 演示样例程序下载:http://pan.baidu.com/s/1gvwlS 暴力破解 观察这个程 ...

  7. hdu5119 Happy Matt Friends(dp)

    题目链接:点击打开链接 题目描写叙述:给出n个数.求从这n个数中随意取出一些数(至少取一个)相互异或之后大于m的方案数? 解题思路:分析因为n<=40&&m<=10^6,因 ...

  8. JDK框架简析--java.lang包中的基础类库、基础数据类型

    题记 JDK.Java Development Kit. 我们必须先认识到,JDK不过,不过一套Java基础类库而已,是Sun公司开发的基础类库,仅此而已,JDK本身和我们自行书写总结的类库,从技术含 ...

  9. ip地址转换成16进制long

    <span style="font-size:18px;">public class IpUtil { /** * ip地址转换成16进制long * @param i ...

  10. 菜鸟nginx源代码剖析数据结构篇(六) 哈希表 ngx_hash_t(上)

    菜鸟nginx源代码剖析数据结构篇(六) 哈希表 ngx_hash_t(上) Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog. ...