【CF39E】【博弈论】What Has Dirichlet Got to Do with That?
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
2 2 10
Masha
5 5 16808
Masha
3 1 4
Stas
1 4 10
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
/*
酒逢知己千杯少,话不投机半句多。
遥知湖上一樽酒,能忆天涯万里人。
*/ #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?的更多相关文章
- CF 39E. What Has Dirichlet Got to Do with That?(记忆化搜索+博弈论)
		
传送门 解题思路 首先很好写出一个\(O(ab)\)的记搜,但发现这样无法处理\(a=1\)和\(b=1\)的情况,这两种情况需要特判.首先\(a=1\)的情况,就是如果当前选手让\(a+1\)必胜, ...
 - IT人生知识分享:博弈论的理性思维
		
背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东( ...
 - LDA( Latent Dirichlet Allocation)主题模型 学习报告
		
1 问题描述 LDA由Blei, David M..Ng, Andrew Y..Jordan于2003年提出,是一种主题模型,它可以将文档集中每篇文档的主题以概率分布的形式给出,从而通过分析一 ...
 - [poj2348]Euclid's Game(博弈论+gcd)
		
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9033 Accepted: 3695 Des ...
 - [综] Latent Dirichlet Allocation(LDA)主题模型算法
		
多项分布 http://szjc.math168.com/book/ebookdetail.aspx?cateid=1&§ionid=983 二项分布和多项分布 http:// ...
 - 博弈论揭示了深度学习的未来(译自:Game Theory Reveals the Future of Deep Learning)
		
Game Theory Reveals the Future of Deep Learning Carlos E. Perez Deep Learning Patterns, Methodology ...
 - TYVJ博弈论
		
一些比较水的博弈论...(为什么都没有用到那什么SG呢....) TYVJ 1140 飘飘乎居士拯救MM 题解: 歌德巴赫猜想 #include <cmath> #include < ...
 - 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 ...
 - 沃罗诺伊图(Voronoi Diagram,也称作Dirichlet tessellation,狄利克雷镶嵌)
		
沃罗诺伊图(Voronoi Diagram,也称作Dirichlet tessellation,狄利克雷镶嵌)是由俄国数学家格奥尔吉·沃罗诺伊建立的空间分割算法.灵感来源于笛卡尔用凸域分割空间的思想. ...
 
随机推荐
- 【转】Eclipse使用git最简易流程
			
原文网址:http://www.cnblogs.com/ZhangWanFan/p/3993733.html git有诸多好处,网上都说的很清楚了,在这里我不再赘述.对于我来说,私下里想做一些项目,而 ...
 - KK的新书《必然》对未来科技趋势的预言
			
是他第一次在<失控>中提示我们-- 要用生物学而不是机械学的角度看待这个世界. 是他第一次在<科技想要什么>提示我们-- 科技本身就是一个生命体. 而在新书<必然 ...
 - 曾经的岁月之maya
 - VS2010 MFC GDI+ 实现PNG透明图片显示
			
网上找了一些资料学习了一下PNG图的显示,这里总结一下. 参考:http://blog.csdn.net/czyt1988/article/details/7965066 一.VS2010配置GDI+ ...
 - UVAlive 3263 That Nice Euler Circuit(欧拉定理)
			
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21363 [思路] 欧拉定理:V+F-E=2.则F=E-V+2. 其 ...
 - Hibernate的Session会话中get()和load()方法的区别
			
1.get和load都可以从数据库中获取数据 .get拿到的是真的对象,load拿到的是代理对象 2.get和load从数据库中获取数据,如果获取不到,get返回null,load会出现ObjectN ...
 - 排序Tip
			
排序算法 所有排序算法汇总:http://en.wikipedia.org/wiki/Sort_algorithm counting sort 资料 :http://www.cs.miami.ed ...
 - Shadow Register 是什么?
			
ARM处理器有个Shadow Register的概念,查了很多资料,语焉不详,究竟是什么意思呢? 这其实是个和硬件有关的概念. 有些register是2层的,第一层是供CPU访问,第二层供Hw访问. ...
 - hdoj 2187 悼念512汶川大地震遇难同胞——老人是真饿了【贪心部分背包】
			
悼念512汶川大地震遇难同胞——老人是真饿了 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
 - nyoj 88 汉诺塔(一)【快速幂】
			
汉诺塔(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度 ...