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. 转---在ASP.NET MVC中实现登录后回到原先的界面

    有这样的一个需求:提交表单,如果用户没有登录,就跳转到登录页,登录后,跳转到原先表单提交这个页面,而且需要保持提交表单界面的数据. 提交表单的页面是一个强类型视图页,如果不考虑需要保持提交表单界面的数 ...

  2. HDU-4920 Matrix multiplication

    矩阵相乘,采用一行的去访问,比采用一列访问时间更短,根据数组是一行去储存的.神奇小代码. Matrix multiplication Time Limit: 4000/2000 MS (Java/Ot ...

  3. xapian搜索系统存储结构解读

    Xapian的database是所有用于检索的信息表的集合,以下的表是必需的: posting list table 保存了被每一个term索引的document,实际上保存的应该是document在 ...

  4. 字符集(CHARACTER SET)和校对集(COLLATE)

    http://blog.sina.com.cn/s/blog_9707fac301016wxm.html http://www.th7.cn/db/mysql/201412/84636.shtml 从 ...

  5. thread.wait的一个好例子

    int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); HelloThread thread; thread.star ...

  6. winform 解决界面闪动、提升加载速度 分类: WinForm 2015-02-03 16:34 161人阅读 评论(0) 收藏

    说明: 从一个技术交流群里获得,经验证效果不错. //作用 加快界面加载 protected override CreateParams CreateParams          {         ...

  7. CSS3弹性盒模型之Flexbox是布局模块box-sizing & box-orient & box-direction & box-ordinal-group

    css3 box-sizing属性 box-sizing属性可以为三个值之一:content-box(default),border-box,padding-box. content-box,bord ...

  8. LeetCode——Linked List Cycle

    Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...

  9. android 17 activity生命周期

    手机指南针传感器处于手机头部. Activity生命周期: 启动. onCreat()方法:初始化布局对象,设置监听器. onstart()方法:注册监听器. onResume():activity已 ...

  10. Android 中 SQLite 性能优化

    数据库是应用开发中常用的技术,在Android应用中也不例外.Android默认使用了SQLite数据库,在应用程序开发中,我们使用最多的无外乎增删改查.纵使操作简单,也有可能出现查找数据缓慢,插入数 ...