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. 【JS学习】数组过滤方法的使用filter

    前言:本博客系列为学习后盾人js教程过程中的记录与产出,如果对你有帮助,欢迎关注,点赞,分享.不足之处也欢迎指正,作者会积极思考与改正. 使用效果: 可以返回参数函数为真的值 //情景:实现从stu数 ...

  2. [mysql]ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value

    转载自:http://www.cnblogs.com/joeblackzqq/p/4526589.html From: http://m.blog.csdn.net/blog/langkeziju/1 ...

  3. 【Oracle】DRM官方介绍

    DRM 简介 By:  Allen Gao 首先,我们对和DRM 相关的一些概念进行介绍. Buffer: 对于RAC 数据库,当一个数据块被读入到buffer cache后,我们就称其为buffer ...

  4. 09--Docker 安装tomcat9

    1.在hub.docker.com中获取tomcat拉取地址 docker pull tomcat:9.0.41-jdk8-corretto 2.查看Dockerfile 中WORKDIR 为/use ...

  5. [CPP] STL 简介

    STL 即标准模板库(Standard Template Library),是 C++ 标准库的一部分,里面包含了一些模板化的通用的数据结构和算法.STL 基于模版的实现,因此能够支持自定义的数据结构 ...

  6. vs code配置vue自动格式化

     vs code配置vue自动格式化 我他妈的要被这个vs code的格式化逼疯了.我在网上看了很多的文章,不是太老就是不好使,遇到太多坑了.在这贴出自己的配置,虽然有多余的代码,虽然可能在未来的更新 ...

  7. 【MYSQL】DDL语句

    介绍:DDL语句,即数据定义语句,定义了不同的数据段,数据库表.表.列.索引等数据库对象:例如,create.drop.alter 适用对象:一般是由数据库管理员DBA使用 1.连接数据库 mysql ...

  8. Python爬虫:数据分析小能手:JSON库的用法

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于人阅读和编写. 给大家推荐一个Python交流的q裙,大家在学习遇到了什么问题都可以进群一起交流,大家 ...

  9. linux--关于JVM CPU资源占用过高的问题排查

    一.背景: 先执行一个java程序里面开了两个线程分别都在while循环做打印操作. # java -cp ./test-threads.jar com.spiro.Main 二.现象: 通过top命 ...

  10. C#高级编程第11版 - 第八章 索引

    [1]8.1 引用方法 1.委托是指向方法的.NET地址变量. 2.委托是类型安全的类,定义了返回类型和参数类型.委托类不单单只包含一个方法引用,它也可以保存多个方法的引用. 3.Lambda表达式直 ...