hdu 4155 The Game of 31 博弈论
给出序列,在剩下的卡中选择,谁先拿到大于31的输,搜一下就可以了!
代码如下:
#include<cstdio>
#include<cstring>
char str[];
int a[],sum;
bool dfs(int m)
{
if(m>=) return ;
for(int i=;i<=;i++){
if(a[i]&&m+i<=){
a[i]--;
if(!dfs(m+i)){
a[i]++;
return ;
}
a[i]++;
}
}
return ;
}
int main()
{
while(scanf("%s",str)!=EOF){
int l=strlen(str);
for(int i=;i<=;i++) a[i]=;
sum=;
for(int i=;i<l;i++){
sum+=str[i]-'';
a[str[i]-'']--;
}
printf("%s ",str);
if(sum>=){
if(l&) puts("A");
else puts("B");
continue;
}
if(dfs(sum)){
if(l&) puts("B");
else puts("A");
}
else{
if(l&) puts("A");
else puts("B");
}
}
return ;
}
hdu 4155 The Game of 31 博弈论的更多相关文章
- HDU 2516 取石子游戏 (博弈论)
取石子游戏 Problem Description 1堆石子有n个,两人轮流取.先取者第1次能够取随意多个,但不能所有取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出" ...
- hdu 4753 Fishhead’s Little Game 博弈论+记忆化搜索
思路:状态最多有2^12,采用记忆化搜索!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm& ...
- hdu 1404/zoj 2725 Digital Deletions 博弈论
暴力打表!! 代码如下: #include<iostream> #include<algorithm> #include<cstdio> #include<c ...
- hdu 1538 A Puzzle for Pirates 博弈论
很经典的问题,思路转载自http://blog.csdn.net/ACM_cxlove?viewmode=contents 题目:这是一个经典问题,有n个海盗,分m块金子,其中他们会按一定的顺序提出自 ...
- hdu 4672 Present Day, Present Time 博弈论
看了解题报告才知道怎么做!! 题意:有 N 堆石子和 M 个石子回收站,每回合操作的人可以选择一堆石子,从中拿出一些 放到石子回收站里(可以放进多个回收站,每个回收站可以使用无数次),但每个石子回收站 ...
- hdu 3032 Nim or not Nim? 博弈论
这题是Lasker’s Nim. Clearly the Sprague-Grundy function for the one-pile game satisfies g(0) = 0 and g( ...
- hdu 1760 A New Tetris Game 博弈论
找sg值,可以选择暴力,也可以利用sg值的特点简化. 暴力就跟取石子一样,没什么差别,DFS搞定.把矩阵看成一个字符串,字符串就是一个状态. 其实我们也可以不暴力求sg值,因为只要当前状态能到达一个s ...
- HDU.1848.Fibonacci again and again(博弈论 Nim)
题目链接 //求三堆石子的SG函数,异或起来就是整个游戏的SG值 #include <cstdio> #include <cstring> const int N=1005; ...
- hdu 1525 Euclid's Game【 博弈论】
Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtra ...
随机推荐
- oracle 各种问题排查
一.ORA-00257 ORA-00257归档日志写满,最简单方法.可以更改归档的大小. 二.job不自动运行解决方法 http://www.cnblogs.com/xbding/p/5861443. ...
- golang构造函数与转换函数
golang的每种类型, 凡是用type定义的类型, 其类型名既是其构造函数,也是其转换函数. 其中,构造函数后眼{...}, 转换函数后跟(...)
- c++ 性能
http://blog.sina.com.cn/s/blog_4a471ff601013vud.html http://www.linuxidc.com/Linux/2015-06/118874.ht ...
- 【分享】生成Revit扩展的addin文件小工具
在进行Revit二次开发的时候,加载命令/程序使用的是添加addin文件的方式,每次都需要手动的写,而且参数有好多,很不方便.于是乎我有了写一个小工具的想法.进过研究终于完成了.主要使用RevitAd ...
- ubuntu14.04建立交叉编译环境, 注意事项
ubuntu14.04建立交叉编译环境, 注意事项 ~$ arm-linux-gcc/opt/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc: 15: e ...
- EF简单的增删查改
Add /// <summary> /// /// </summary> public void Add() { TestDBEntities2 testdb = new Te ...
- PHP URL 重定向 的三种方法(转载)
为了方便查询,转载一篇. 1.使用header()函数 PHP的HTTP相关函数种提供了一个 header()函数,首先要清楚,header()函数必须放在php程序的开头部分,而且之前不能有另 ...
- Min Stack
Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constan ...
- week 9 scenario testing
1:How do you expect different personas to use your software? What’s their need and their goals, ho ...
- nscd
作用: Nscd is a daemon that provides a cache for the most common name service requests 可以缓存passwd,grou ...