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)可以利用现 ...
随机推荐
- 3.Pycharm和navicate的使用
Pycharm的下载 进入到Pycharm官网,进入网页的最下边,下载企业版enterprise(可试用30天),企业版提供了创建项目.run等功能,而免费版没有这些功能 pycharm的使用: 在f ...
- window.open、window.showModalDialog和window.showModelessDialog 的区别[转]
一.前言 要打开一个可以载入页面的子窗口有三种方法,分别是window.open.window.showModalDialog和window.showModelessDialog. open方法就是打 ...
- OSGi类加载问题
项目中遇到的JVM难点 ——启动OSGi容器时,出现永久代内存不够.内存泄露 ——OSGi找不到类路径问题. ——线程死锁问题. 问题一:OSGi类内存问题 其次,从内存用量来看, ...
- MDX跨cube查询——lookupcube
关于SSAS中从多个cube中查询数据 前提:涉及的cube在同一数据库中,维度共享(最好) SSAS中提供一条mdx语句同时从多个cube中查询数据的功能 实现该功能的就是lookupcube函数, ...
- CentOS 6.6 中jdk1.6的安装和配置方法
Linux中JDK1.6的安装和配置方法 一.安装 创建安装目录,在/usr/java下建立安装路径,并将文件考到该路径下: # mkdir /usr/java 1.jdk-6u11-linux-i5 ...
- DOM的的概述
DOM= Document Object Model,文档对象模型,DOM可以以一种独立于平台和语言的方式访问和修改一个文档的内容和结构.换句话说,这是表示和处理一个HTML或XML文档的常用方法.有 ...
- requests 简单应用
http://docs.python-requests.org/zh_CN/latest/user/quickstart.html ,官方文档.自己有空看看顺便敲两下熟悉一下. 还有别把文件放的太深 ...
- 【微信小程序+ES6新特性应用】字符串模板:美元符号$+大括号{}变量的写法
1.字符串模板简介 ES6新特性中的字符串模板允许使用英文字符抑音符号`(提示:这里我们不能将其理解为单引号)来创建字符串,并且在该字符串中可以包含都[美元符号+大括号]包裹的变量 格式:consol ...
- 分布式_理论_01_CAP定理
一.前言 五.参考资料 1.分布式理论(一) - CAP定理——零壹技术栈 2.分布式理论(一) —— CAP 定理——莫那一鲁道 3.分布式系统理论基础 - CAP 4.分布式系统的CAP理论
- PHP用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID
向mysql 插入数据时,很多时候我们想知道刚刚插入数据的id,这对我们很有用.下面这篇文章就详细给大家介绍了利用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID,有需要的朋友 ...