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. 7.prometheus之查询API

    一.格式概述 二.表达式查询 2.1 Instant queries(即时查询) 2.2 范围查询 三.查询元数据 3.1 通过标签匹配器找到度量指标列表 3.2 获取标签名 3.3 查询标签值 四. ...

  2. 机器学习1-sklearn&字典特征抽取

    sklearn数据集 数据集API介绍 sklearn.datasets 加载获取流行数据集 datasets.load_*() 获取小规模数据集,数据包含在datasets里 datasets.fe ...

  3. appium识别工具介绍

  4. 18.java设计模式之中介者模式

    基本需求 智能家庭包括各种设备,闹钟.咖啡机.电视机.窗帘等 要看电视时,各个设备可以协同工作,自动完成看电视的准备工作,比如流程为:闹铃响起->咖啡机开始做咖啡->窗帘自动落下-> ...

  5. 更改mysql的密码

    mysql> set password for 'root'@'localhost' =PASSWORD('');Query OK, 0 rows affected (0.17 sec) mys ...

  6. UVM基础总结——基于《UVM实战》示例

    一.前言 工作一直在做SoC验证,更关注模块间的连接性和匹配性,所以相比于擅长随机约束激励的UVM来说,定向测试的概念更容易debug.当然前提是IP已经被充分验证.因此觉得接触UVM的机会较少.到现 ...

  7. 日常分享:关于时间复杂度和空间复杂度的一些优化心得分享(C#)

    前言 今天分享一下日常工作中遇到的性能问题和解决方案,比较零碎,后续会持续更新(运行环境为.net core 3.1) 本次分享的案例都是由实际生产而来,经过简化后作为举例 Part 1(作为简单数据 ...

  8. 阅读lodash源码之旅数组方法篇-compact和concat

    鲁迅说过:只有阅读过优秀库源码的人,才能配的上是真正的勇士. compact 创建一个新数组,包含原数组中所有的非假值元素.例如false, null,0, "", undefin ...

  9. Hive常用性能优化方法实践全面总结

    Apache Hive作为处理大数据量的大数据领域数据建设核心工具,数据量往往不是影响Hive执行效率的核心因素,数据倾斜.job数分配的不合理.磁盘或网络I/O过高.MapReduce配置的不合理等 ...

  10. C++学习之STL(一)vector

    前言 C++ Primer Plus读书笔记(三)复合类型 中已经简单介绍过vector是什么,这个系列主要是介绍STL特性. 声明 vector<ElemType> c; //创建一个空 ...