Description

You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.

Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.

Who loses if both players play optimally and Stas's turn is first?

Input

The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.

Output

Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".

Sample Input

Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing

Hint

In the second example the initial number of ways is equal to 3125.

  • If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
  • But if Stas increases the number of items, then any Masha's move will be losing.

Source

【分析】
还不错的题目,跟普通的题目有区别的是有平局的情况。
需要特判一下。
如a = 1的时候,如果两个人都在b上面操作,就不会有结果。
所以模拟一下b的增加然后判断增加1的时候的胜败态就行了。
还有b = 1时同理。
还有就是a b 同时为1的时候
 /*
酒逢知己千杯少,话不投机半句多。
遥知湖上一樽酒,能忆天涯万里人。
*/ #include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define LOCAL
const int MAXL = ;
const long long MOD = ;
const int MAXK = + ;
const int MAXN = + ;
const int MAXM = ;
using namespace std;
typedef long long LL;
int a , b , n , sg[MAXN][MAXM]; LL pow(int a, int b){
if (b == ) return 1ll;
if (b == ) return (LL)a;
LL tmp = pow(a, b / );
if (b % == ) return tmp * tmp;
else return (LL)tmp * tmp * (LL)a;
}
int dfs (int a , int b) {
if (sg[a][b] >= ) return sg[a][b];
if (pow(a, b) >= (LL)n) {
return sg[a][b] = ;
}
int Ans = ;
Ans |= !dfs(a + , b);//只要有一个是1就能够获胜
Ans |= !dfs(a , b + );
return sg[a][b] = Ans;
}
int work_2(int a){
int b = , turn = ;
int up = (int)sqrt((double)n - 0.0000001);//处理上界
while (a <= up){
if (sg[a][b + ] == ) return (turn == );
a++;
turn = turn ^ ;
}
//剩下的就是判断奇偶性,看谁先到
turn = (turn + (n - - a)) % ;
return turn;
}
int work_1(int b){
int a = ;
if (pow(a, b) >= n) return ;
else {
int turn = ;
for (; !(pow(, b) >= n); b++){
if (sg[a + ][b] == ){
if (turn == ) return ;
else return -;
}
turn ^= ;
}
return ;
}
} int main () { memset(sg , - , sizeof (sg));
scanf("%d%d%d", &a, &b, &n);
if (pow(a, b) >= n) {
puts ("Masha");
return ;
}
dfs(, );
if (a != && b != ){
if (sg[a][b] != ) printf("Masha");
else printf("Stas");
return ;
} if (a == && b == ){
int c = work_1(b + );
int d = work_2(a + );
if (c < || d == ) printf("Masha");
else if (c == ) printf("Missing");
else printf("Stas");
}else if (b == ){
if (work_2(a) != ) printf("Masha");
else printf("Stas");
}else if (a == ){
int tmp = work_1(b);
if (tmp == ) printf("Missing");
else if (tmp == ) printf("Masha");
else printf("Stas");
}
return ;
}

【CF39E】【博弈论】What Has Dirichlet Got to Do with That?的更多相关文章

  1. CF 39E. What Has Dirichlet Got to Do with That?(记忆化搜索+博弈论)

    传送门 解题思路 首先很好写出一个\(O(ab)\)的记搜,但发现这样无法处理\(a=1\)和\(b=1\)的情况,这两种情况需要特判.首先\(a=1\)的情况,就是如果当前选手让\(a+1\)必胜, ...

  2. IT人生知识分享:博弈论的理性思维

    背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东( ...

  3. LDA( Latent Dirichlet Allocation)主题模型 学习报告

    1     问题描述 LDA由Blei, David M..Ng, Andrew Y..Jordan于2003年提出,是一种主题模型,它可以将文档集中每篇文档的主题以概率分布的形式给出,从而通过分析一 ...

  4. [poj2348]Euclid's Game(博弈论+gcd)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9033   Accepted: 3695 Des ...

  5. [综] Latent Dirichlet Allocation(LDA)主题模型算法

    多项分布 http://szjc.math168.com/book/ebookdetail.aspx?cateid=1&&sectionid=983 二项分布和多项分布 http:// ...

  6. 博弈论揭示了深度学习的未来(译自:Game Theory Reveals the Future of Deep Learning)

    Game Theory Reveals the Future of Deep Learning Carlos E. Perez Deep Learning Patterns, Methodology ...

  7. TYVJ博弈论

    一些比较水的博弈论...(为什么都没有用到那什么SG呢....) TYVJ 1140  飘飘乎居士拯救MM 题解: 歌德巴赫猜想 #include <cmath> #include < ...

  8. Codeforces 549C. The Game Of Parity[博弈论]

    C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. 沃罗诺伊图(Voronoi Diagram,也称作Dirichlet tessellation,狄利克雷镶嵌)

    沃罗诺伊图(Voronoi Diagram,也称作Dirichlet tessellation,狄利克雷镶嵌)是由俄国数学家格奥尔吉·沃罗诺伊建立的空间分割算法.灵感来源于笛卡尔用凸域分割空间的思想. ...

随机推荐

  1. scanf从文件中读入,printf写入到文件

    重定向方式读写文件 #include <stdio.h> #define LOCAL int main() { #ifdef LOCAL freopen("input.txt&q ...

  2. hdu 4403 枚举

    #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #inclu ...

  3. Java GC专家系列2:Java 垃圾回收的监控

    这是”成为GC专家系列”文章的第二篇.在第一篇理解Java垃圾回收中我们学习了几种不同的GC算法的处理过程,GC的工作方式,新生代与老年代的区别.到目前为止,你应该已经了解了JDK 7中的5种GC类型 ...

  4. Google网页搜索

    本博文的主要内容有 .Google网页搜索的介绍 .Google网页搜索的使用偏好设置 .Google网页搜索的普通搜索 .Google网页搜索的高级搜索 .Google高级搜索之一:布尔逻辑搜索   ...

  5. UVA 465 (13.08.02)

     Overflow  Write a program that reads an expression consisting of twonon-negative integer and an ope ...

  6. Winform Windows Media Player 简易播放器 分类: WinForm 2014-07-31 20:12 589人阅读 评论(0) 收藏

    新手上路,高手勿进! 窗体设计: 实现效果: 实现代码: using System; using System.Collections.Generic; using System.ComponentM ...

  7. (配置)CKEditor+CKFinder+php上传配置,根据年月命名创建文件夹来存放

    CKEditor+CKFinder+php上传配置 新版本的CKEditor只提供了基本的文本编辑功能,上传模块由另一个组件CKFinder.这里主要记录CKFinder上传的一些参数配置,能够成功上 ...

  8. ASP.NET通过http/https的POST方式,发送和接受XML文件内容

    本文转载:http://hi.baidu.com/ysyhyt/item/5011ae39ce3cf49fb80c0395 本文参考:http://blog.csdn.net/ououou123456 ...

  9. Android教程:ImageView 设置图片

    Android doc中是这样描述的: public void setImageResource (int resId) 这是其中的一个方法,参数resld是这样: ImageView.setImag ...

  10. strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏

    (一) strace 命令    用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...