Topic Links: Click the open link
Serie A champions:
Specific a box B ball does not change n (Ball and box are not the same, kind of goods)
Set way = Number of methods to put the B ball into a box, the end of the game if it >= N
There are 2 of people playing games.
If the current turn is X
1. x Select Add a box or add a ball
2, if the number of methods after adding >=n X failed
If the initiator wins, then output Masha, if the initiator will be defeated output Stas, if the draw is output Missing
Ideas:
Memory Search
If the current to a++ or b++ are >=n, the current situation will be defeated
From the situation that will not >=n.
Note that if there is only one box. and add a box will be >=n, then must only add B, then there must be no solution
If there is only one ball, and then add a ball to the case of no solution, then only can add a, then according to the parity of n-a can be to the current situation
#include <cstdio> #include <iostream> #include <string.h> #include <map>using namespace std;# Define ll long Longll N, a, B;bool win (ll X, ll y) {//X box y ball This point is a must-fail ll tmp = 1; for (ll i = 1; I <= y; i++) {tmp*=x; if (tmp>=n) return true; } return false;} map<pair<ll,ll>, ll> mp;ll dfs (ll x, ll y) {//The state of this point if (Mp.find (pair<ll,ll> (x, y)! = Mp.end ()) return mp[pair<ll,ll> (x, y)]; if (X==1 && win (2, y)) return mp[pair<ll,ll> (x, y)] =-1; if (Y==1 && win (x,2)) {if ((n-x) &1) return mp[pair<ll,ll> (x, y)] = 0; return mp[pair<ll,ll> (x, y)] = 1; } if (Win (x, y)) return mp[pair<ll,ll> (x, y)] = 1; ll u = Win (x+1,y), V = Win (x,y+1); if (u==1&&v==1) return mp[pair<ll,ll> (x, y)] = 0; if (U = = 0) u = DFS (x+1, y); if (v = = 0) v = DFS (x, y+1); if (U = = 0 | | v = = 0) return mp[pair<ll,ll> (x, y)] = 1; if (u==-1| | V==-1) REturn mp[pair<ll,ll> (x, y)] =-1; return mp[pair<ll,ll> (x, y)] = 0;} int main () {ll A, B; while (cin>>a>>b>>n) {mp.clear (); if (Win (A+1,B) && win (a,b+1)) {puts ("Stas"); Continue } if (B==1 && win (a,2)) {if (!) ( (n-a) &1) puts ("Masha"); Else puts ("Stas"); Continue } ll tmp = DFS (A, b); if (tmp<0) puts ("Missing"); else tmp? Puts ("Masha"):p UTS ("Stas"); } return 0;}
Codeforces 39E What have Dirichlet Got to does with? Games + Memory Search