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. mkfs 的使用

    使用方法: [root@localhost beinan]# mkfs -t 文件系统  存储设备 注:这里的文件系统是要指定的,比如 ext3 :reiserfs :ext2 :fat32 :msd ...

  2. Python中With的用法

    在看Dive Into Python中有关描述文件读写那章节的时候,看到了有关with的用法,查阅下相关资料,记录下来,以备后用. 官方的reference上有关with statement是这样说的 ...

  3. 天津Uber优步司机奖励政策(1月18日~1月24日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  4. 动态更换view类的背景---StateListDrawable的应用

    StateListDrawable可以根据View的不同状态,更换不同的背景 可以应用如EditText,Button等中,以Button为例 系统中默认的按钮被按下的颜色和未点击时的颜色不一样,该种 ...

  5. SpringMVC存取Session的两种方法 转

    方法一:使用servlet-api @Controller public class ManagerController { @Resource private ManagerService mana ...

  6. redis中各种数据类型对应的jedis操作命令

    redis中各种数据类型对应的jedis操作命令 一.常用数据类型简介: redis常用五种数据类型:string,hash,list,set,zset(sorted set). 1.String类型 ...

  7. jquery 实现页面拖拽并保存到cookie

    实现的效果就是页面内的图片可拖拽到任意位置,并将所在位置保存.下次打开页面依然可见.本文是作demo用,实际开发中,位置的数据应保存到数据库中. 好了,开始. 1.准备工作. a.jquery(1.7 ...

  8. 设置imageView正方形高宽

    private void initWidth() { int screenWidth = ((MyApplication)getApplication()).screenWidth; if(0 == ...

  9. 基于Visual C++2012拆解世界五百强面试题--题3

    请用C语言实现 输入N,打印N*N矩阵 比如 N = 3, 打印: 1 2 3 8 9 4 7 6 5 N = 4, 打印 1   2    3   4 12  13   14  5 11  16   ...

  10. [Javascript] Modifying an Immutable.js Map()

    We will now look at five methods that modify an Immutable.Map(). set update delete clear merge //set ...