codeforce -39E-What Has Dirichlet Got to Do with That?(博弈+dfs)
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
2 2 10
Masha
5 5 16808
Masha
3 1 4
Stas
1 4 10
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)的更多相关文章
- CF 39E What Has Dirichlet Got to Do with That? (博弈)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:给出a ^ b,两个人轮流操作,可以 a ...
- Codeforces 39E What Has Dirichlet Got to Do with That? 游戏+内存搜索
主题链接:点击打开链接 意甲冠军: 特定 a一箱 b球 不变n (球和箱子都不尽相同,样的物品) 设 way = 把b个球放到a个箱子中的方法数, 若way >= n则游戏结束 有2个人玩游戏. ...
- CF 39E. What Has Dirichlet Got to Do with That?(记忆化搜索+博弈论)
传送门 解题思路 首先很好写出一个\(O(ab)\)的记搜,但发现这样无法处理\(a=1\)和\(b=1\)的情况,这两种情况需要特判.首先\(a=1\)的情况,就是如果当前选手让\(a+1\)必胜, ...
- D. New Year Santa Network 解析(思維、DFS、組合、樹狀DP)
Codeforce 500 D. New Year Santa Network 解析(思維.DFS.組合.樹狀DP) 今天我們來看看CF500D 題目連結 題目 給你一棵有邊權的樹,求現在隨機取\(3 ...
- LDA( Latent Dirichlet Allocation)主题模型 学习报告
1 问题描述 LDA由Blei, David M..Ng, Andrew Y..Jordan于2003年提出,是一种主题模型,它可以将文档集中每篇文档的主题以概率分布的形式给出,从而通过分析一 ...
- [综] Latent Dirichlet Allocation(LDA)主题模型算法
多项分布 http://szjc.math168.com/book/ebookdetail.aspx?cateid=1&§ionid=983 二项分布和多项分布 http:// ...
- 沃罗诺伊图(Voronoi Diagram,也称作Dirichlet tessellation,狄利克雷镶嵌)
沃罗诺伊图(Voronoi Diagram,也称作Dirichlet tessellation,狄利克雷镶嵌)是由俄国数学家格奥尔吉·沃罗诺伊建立的空间分割算法.灵感来源于笛卡尔用凸域分割空间的思想. ...
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- 关于Beta分布、二项分布与Dirichlet分布、多项分布的关系
在机器学习领域中,概率模型是一个常用的利器.用它来对问题进行建模,有几点好处:1)当给定参数分布的假设空间后,可以通过很严格的数学推导,得到模型的似然分布,这样模型可以有很好的概率解释:2)可以利用现 ...
随机推荐
- vRA7 Software Component
将自定义Property传递给Software Component 示例: vRA7 支持 Software Components,并且还可以在用户的申请页面中,做一个下拉菜单,让用户选择需要安装的S ...
- Java线程池ExecutorService和CountDownLatch的小例子
import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java ...
- streambase service 变为 window service启动
1.配置出.sbdeploy文件 2.安装streambase服务 streambase command line :--install-service 即可安装对应的的window service ...
- thinkphp判断更新是否成功
如何判断一个更新操作是否成功 $Model = D('Blog'); $data['id'] = 10; $data['name'] = 'update name'; $result = $Model ...
- js的constructor
js创建一个构造函数,会默认在原型链上添加一个constructor的属性,它保存了构造函数内的代码. 一般情况下我们不需要去改动它,但是有些时候我们会不经意的改写它. 比如下面这个例子: var F ...
- 强制关闭iPhone iPad AppleWatch MacOS
iPhone/iPad 强制关闭APP:按住Power(电源键),出现关机界面松开,按住Home键9秒左右. 强制重启/关机:同时按住Power和Home键几秒后重启,出现logo时松开Home继续按 ...
- linux设置开机自动进入命令模式
1)打开终端,输入命令: su – root 2)输入密码 3)再输入如下命令进入到命令行模式: init 3 4)修改启动模式为永久命令行模式: vi /etc ...
- ADO.NET异步操作测试
配置文件: <?xml version="1.0"?> <configuration> <startup> <supportedRunti ...
- PCA算法详解——本质上就是投影后使得数据尽可能分散(方差最大),PCA可以被定义为数据在低维线性空间上的正交投影,这个线性空间被称为主⼦空间(principal subspace),使得投影数据的⽅差被最⼤化(Hotelling, 1933),即最大方差理论。
PCA PCA(Principal Component Analysis,主成分分析)是一种常用的数据分析方法.PCA通过线性变换将原始数据变换为一组各维度线性无关的表示,可用于提取数据的主要特征分量 ...
- P2152 [SDOI2009]SuperGCD (luogu)
Stein算法是一种计算两个数最大公约数的算法,是针对欧几里德算法在对大整数进行运算时,需要试商导致增加运算时间的缺陷而提出的改进算法. 算法思想: 由J. Stein 1961年提出的Stein算法 ...