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. iOS如何获取蓝牙Mac地址

    http://macpu.github.io/2015/11/12/iOS%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E8%93%9D%E7%89%99Mac%E5%9C ...

  2. ActiveMQ部署和503的错误

    最近部署ActiveMQ的时候,发现有的服务器可以打开后台管理网址,有的服务器无法打开,Jetty报503 Service Unavailable. 搞了很久终于发现了问题,现将部署和解决过程做笔记如 ...

  3. QT 布局时使用 addStretch 可伸缩设置

    今天在使用addStretch,布局的时候,发现addStretch竟然是可以平均分配的,有意思.比如: QVBoxLayout *buttonLayout = new QVBoxLayout; bu ...

  4. Mirantis对OpenStack的性能测试:高并发创建75000台虚拟机

    硅谷创业公司Mirantis不久前进行了一项基准测试,测试在OpenStack Havana版本上创建75000台虚拟机的性能数据.就启动时间和成功率而言,当应用250个并发部署75000台虚拟机是最 ...

  5. spring boot 基础篇 -- 阿里多数据源

    这块是比较基础的配置,阿里数据库配置还是比较好用的,并且可以用来监控数据源的情况.废话不多说,下面看代码. 基于maven项目,在pom.xml中添加引用: <dependency> &l ...

  6. 详解 Android 通信

    详解 Android 通信 :http://www.androidchina.net/5028.html

  7. Hive group by实现-就是word 统计

    准备数据 SELECT uid, SUM(COUNT) FROM logs GROUP BY uid; hive> SELECT * FROM logs; a 苹果 5 a 橙子 3 a 苹果 ...

  8. Hibernate(2)

    一.实体类编写规则 1.实体类里面的属性属于私有的 2.私有属性使用公开的set和get方法操作 3.要求实体类有属性作为唯一值(一般使用id值) 4.实体类属性建议不要使用基本数据类型,使用基本数据 ...

  9. linux monitor and maintanence

    @cacti 1.install epel extends source 2.install lamp use yum method yum install -y httpd php php-mysq ...

  10. (转)轻量级C语言实现的minixml解析库入门教程

    svn上的minixml源码下载:svn co http://svn.msweet.org/mxml/tags/release-2.7/ 按照下载回来的源代码进行编译和安装.本教程只针对新手做一个引导 ...