【HDU】1517 A Multiplication Game

http://acm.hdu.edu.cn/showproblem.php?pid=1517

题意:每次乘上2~9。。p>=n时赢..

#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

typedef long long ll;
map<ll, bool> h;
ll n;
bool dfs(ll p) {
	if(p>=n) return 0;
	if(h.count(p)) return h[p];
	for(int i=2; i<=9; ++i) if(!dfs(p*i)) return h[p]=1;
	return h[p]=0;
}
int main() {
	while(~scanf("%lld", &n)) {
		h.clear();
		dfs(1)?puts("Stan wins."):puts("Ollie wins.");
		//for(int i=1; i<=16; ++i) printf("%d: %d\n", i, h[i]);
	}
	return 0;
}

  


 

由于乘法在2~9的话深度是log级的= =而且很多无用状态= =开个map裸跑= =

 

posted @ 2015-02-06 22:30  iwtwiioi  阅读(178)  评论(0编辑  收藏  举报