码迷,mamicode.com
首页 > 其他好文 > 详细

【HDU】1517 A Multiplication Game

时间:2015-02-06 23:11:08      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

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裸跑= =

 

【HDU】1517 A Multiplication Game

标签:

原文地址:http://www.cnblogs.com/iwtwiioi/p/4278136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!