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".

Examples

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

Note

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.

题意:(a+x)^(b+y)>n,输出败者

dfs遍历每一种情况,递归到底之后回溯。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool kp(ll a,ll b,ll n)
{
ll r=;
while(b)
{
if(b&)r=r*a;
if(r>=n||a>=n)return ;
a=a*a;b=b/;
}
return ;
}
int dfs(ll a,ll b,ll n)//dfs(a,b,n)表示当参数为a,b,n时对于先手的状态。
{
bool k1=kp(a+,b,n),k2=kp(a,b+,n);
if(a==&&!k1)return ;//平局
if(k2&&!dfs(a,b+,n))return ;//把败态转移给对方
if(k1&&!dfs(a+,b,n))return ;//同上
if(k1&&dfs(a+,b,n)==)return ;//无法把败态转移给对方但是可以维持平局
if(k2&&dfs(a,b+,n)==)return ;//同上
return ;//无论怎样操作都把胜态留给对手
}
int main()
{
ll a,b,n;scanf("%lld%lld%lld",&a,&b,&n);
int t=dfs(a,b,n);
if(t==)printf("Masha\n");
else if(t==)printf("Stas\n");
else printf("Missing\n");
return ;
}

codeforce -39E-What Has Dirichlet Got to Do with That?(博弈+dfs)的更多相关文章

  1. CF 39E What Has Dirichlet Got to Do with That? (博弈)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出a ^ b,两个人轮流操作,可以  a ...

  2. Codeforces 39E What Has Dirichlet Got to Do with That? 游戏+内存搜索

    主题链接:点击打开链接 意甲冠军: 特定 a一箱 b球 不变n (球和箱子都不尽相同,样的物品) 设 way = 把b个球放到a个箱子中的方法数, 若way >= n则游戏结束 有2个人玩游戏. ...

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

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

  4. D. New Year Santa Network 解析(思維、DFS、組合、樹狀DP)

    Codeforce 500 D. New Year Santa Network 解析(思維.DFS.組合.樹狀DP) 今天我們來看看CF500D 題目連結 題目 給你一棵有邊權的樹,求現在隨機取\(3 ...

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

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

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

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

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

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

  8. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  9. 关于Beta分布、二项分布与Dirichlet分布、多项分布的关系

    在机器学习领域中,概率模型是一个常用的利器.用它来对问题进行建模,有几点好处:1)当给定参数分布的假设空间后,可以通过很严格的数学推导,得到模型的似然分布,这样模型可以有很好的概率解释:2)可以利用现 ...

随机推荐

  1. juniper设置共享上网(注意事项)

    注意:出去的 策略  ,勾上  NAT 选项  

  2. sg函数的应用

    刚刚接触到sg函数突然感觉到原来可以这么好用,sg函数应该算是博弈论中比较经典的东西了.下面来说说sg函数: 从网上搜集资料终于能看懂了下面解释来自http://www.cnblogs.com/cj6 ...

  3. Owin and Startup class

    https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection ...

  4. Crashlytics功能集成

    总共分三步: 1. 将Crashlytics.framework和Fabric.framework拷贝到工程中: 2.配置工程的info.plist文件,如下: APIKey和Build secret ...

  5. BZOJ4654/UOJ223 [Noi2016]国王饮水记

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  6. list!=null跟list.isEmpty()有什么区别?

    这就相当与,你要喝水,前面list!=null就是判断是不是连水杯都没有,后面!list.isEmpty就是判断水杯里面没有水,连盛水的东西都没有,这个水从何而来?所以一般的判断是if(list!=n ...

  7. JDBC方式操作数据库

    1.读取配置文件,我将配置信息写入配置文件(.properties)中,方便后期数据库变更后或者其他项目使用,扩展性好些,尽量避免硬编码. driver=oracle.jdbc.driver.Orac ...

  8. QT5 QtreeWidget 实现点击item事件以及右键菜单删除item 和 重命名item

    1.new 一个QTreeWidget 对象,并设置头标签,和根节点(个人程序需要) QTreeWidget* treeWidget = ui.treeWidget;//我已经在ui设计师中拖了一个Q ...

  9. 五一清北学堂培训之Day 3之DP

    今天又是长者给我们讲小学题目的一天 长者的讲台上又是布满了冰红茶的一天 ---------------------------------------------------------------- ...

  10. Spring boot临时文件目录报错

    基本的错误信息如下: 2018-03-05 at 15:12:03 CST ERROR org.apache.juli.logging.DirectJDKLog 181 log - Servlet.s ...