【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,狄利克雷镶嵌)是由俄国数学家格奥尔吉·沃罗诺伊建立的空间分割算法.灵感来源于笛卡尔用凸域分割空间的思想. ...
随机推荐
- 10.8 OSInstall破解
解决 无法完成您的购买,不兼容的问题 http://pan.baidu.com/share/link?shareid=2396730945&uk=1764629622
- Move Zeroes——Leetcode
Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...
- 【转】unity3d input输入
Input 输入 按键 Input.GetKey(“up”) = Input.GetKey(KeyCode.UpArrow) 按住键盘上键 Input.GetKeyDown (“up”) 按下键盘上键 ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- UIColor的使用
UIColor主要在设置各个控件的颜色的时候用得到,主要有以下几种方法创建UIColor: 1.使用RGBA创建: greenbluealpha]; 2.直接创建各个常用颜色: [UIColo ...
- 一个cocos2d程序的完整人生(从环境到代码全过程)
今天我的打砖块小游戏Beta0.1终于完成了,比较开心,写一下这个程序从出生到长大的全过程把. 这是个博客集合帖,具体的操作细节我都在其它博文中有详细说明,下面会给出链接 首先,我想我还是要介绍一 ...
- Android View 事件分发机制详解
想必很多android开发者都遇到过手势冲突的情况,我们一般都是通过内部拦截和外部拦截法解决此类问题.要想搞明白原理就必须了解View的分发机制.在此之前我们先来了解一下以下三个非常重要的方法: di ...
- Counting - SGU 117(快速幂)
题目大意:求下面N个数里面有多少个数的M次方能整除K 代码如下: ======================================================== #include&l ...
- Epoll之ET、LT模式
Epoll之ET.LT模式 在使用epoll时,在函数 epoll_ctl中如果不设定,epoll_event 的event默认为LT(水平触发)模式. 使用LT模式意味着只要fd处于可读或者可写状态 ...
- 常用文件操作 分类: C# 2014-10-14 16:18 108人阅读 评论(0) 收藏
界面图: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...