Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 4601    Accepted Submission(s): 2609


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.
 
题意:给你一个数n,1 < n < 4294967295,起始数是1,两个人玩游戏,每人可以在起始点上乘上2~9的任何一个数,谁先乘一个数大于等于n就获胜,问哪一个必胜。
思路:这题的要点是理解必胜点和必败点,当一个点的后继点至少有一个是必败点那么这点是必胜点,当一个点的后继点全部都是必胜点那么该点是必败点。因为我们只需要判断1是必胜点还是必败点,所以只要从1开始深搜就行了,为了防止超时,我们用map<int,node>mp中的node记录这个数是不是访问过了并且它是必胜点还是必败点。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
struct node{
int vis,sg;
};
map<int,node>mp;
ll n;
int dfs(ll num)
{
int i,j;
int flag;
if(num*9>=n){
mp[num].vis=1;
mp[num].sg=1;
return 1;
}
mp[num].vis=1;
for(i=2;i<=9;i++){
if(mp[num*i].vis==1){
if(mp[num*i].sg==0){
mp[num].sg=1;break;
}
}
else{
dfs(num*i);
if(mp[num*i ].sg==0){
mp[num].sg=1;break;
}
}
}
return mp[num].sg;
} int main()
{
ll m,i,j,ll;
while(scanf("%lld",&n)!=EOF)
{
mp.clear();
if(dfs(1)==0)printf("Ollie wins.\n");
else printf("Stan wins.\n");
}
return 0;
}

hdu1517 A Multiplication Game的更多相关文章

  1. POJ2505 A multiplication game[博弈论]

    A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6028   Accepted:  ...

  2. 【数学】Matrix Multiplication

                                 Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  3. hdu 4920 Matrix multiplication bitset优化常数

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  4. 矩阵乘法 --- hdu 4920 : Matrix multiplication

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  5. Booth Multiplication Algorithm [ASM-MIPS]

    A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...

  6. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

  7. hdu4920 Matrix multiplication 模3矩阵乘法

    hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  8. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  9. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...

随机推荐

  1. Python绘制雷达图(俗称六芒星)

    原文链接:https://blog.csdn.net/Just_youHG/article/details/83904618 背景 <Python数据分析与挖掘实战> 案例2–航空公司客户 ...

  2. 攻防世界—pwn—guess_num

    题目分析 checksec检查文件保护机制 这个结果看的我满是问号??? \n ida分析程序 是一个猜数字的游戏,需要全部输入正确才能得到flag 根据大佬的wp得出一下内容 先使用srand()进 ...

  3. 【葵花宝典】kolla部署OpenStack-AllinOne

    1.关闭防火墙以及内核安全机制 systemctl stop firewalld systemctl disable firewalld ##永久性关闭 setenforce 0 sed -i 's/ ...

  4. Windows程序通用自动更新模块(C#,.NET4.5以上)

    本通用自动更新模块适合所有Windows桌面程序的自动更新,不论语言,无论Winform还是wpf. 一.工作流程:1. 主程序A调起升级程序B2. B从服务器获取更新程序列表,打印更新信息.3. B ...

  5. 面试时通过volatile关键字,全面展示线程内存模型的能力

    面试时,面试官经常会通过volatile关键字来考核候选人在多线程方面的能力,一旦被问题此类问题,大家可以通过如下的步骤全面这方面的能力.     1 首先通过内存模型说明volatile关键字的作用 ...

  6. tail -f 在对文件进行动态追踪时失效的问题

    在我是用 tail -f file.txt 对这个文件进行动态追踪时: 我重新打开一个新的终端进行vim编辑这个文件并且保存 这是我们发现,tail -f file.txt'动态追踪的这个文件没有任何 ...

  7. python(paramiko模块的简单使用)

    #通过paramiko模块连接主机运行bash命令 import paramiko hostname = '192.168.88.31' port = 22 username = 'root' pas ...

  8. Windows Server 2012 R2 英文版汉化安装中文语言包教程更改为中文版

    是这样的,一台海外的windows机器默认是英文版的,但是特别费劲用起来,就更改为中文版,因为海外的供应商并不提供中文版镜像. 1.首先打开控制面板,找到add language,拉到底就是有中文,很 ...

  9. 向HDFS中上传任意文本文件,如果指定的文件在HDFS中已经存在,由用户指定是追加到原有文件末尾还是覆盖原有的文件

    1 import java.io.FileInputStream; 2 import java.io.IOException; 3 import java.util.Scanner; 4 5 impo ...

  10. JAVA中关于基本数据和引用数据参数传递过程

    基本数据和引用数据参数传递过程 案例1:判断程序的输出结果 class Demo{ public static void main(String[] atgs){ int x =4; show(x); ...