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 ...
随机推荐
- 配置 apt-get cloudera 离线source(Cloudera Manager的源)
配置 apt-get cloudera 离线source(Cloudera Manager的源) 创建/etc/apt/source.list.d/cloudera-manager.list文件,并在 ...
- iOS学习之C语言函数
一.函数的定义 返回值类型 函数名(参数类型 参数名, ...) { 功能语句; return 返回值; } 按照返回值和参数划分: 第一种: 无返回值 无参 void sayHello() { pr ...
- 15.Cyclone II的IO资源学习
IO资源 IO是与外界沟通和控制的通道,fpga提供了丰富的IO和一些实用的特性. 本文简要的将主要的特性摘录下来做设计参考用.具体参数参考handbook. 第一部分:IO特性概述 -----通过软 ...
- Ubuntu 关闭锁屏界面的 on-screen keyboard
试了试屏幕键盘,在 系统设置里开启了,又关了,但是在屏幕解锁时总是出现 screen keyboard,老烦人了,不知到在哪里关闭了,系统设置里面都关了,网上搜了解决办法,原来在这里 把 show w ...
- OO之工厂模式
以下为工厂模式的详解,包括简单工厂,普通工厂模式,抽象工厂. 引子: 假设有一个交通工具公司,生产自行车,汽车,飞机等,现要销售该公司的产品,要怎么设计呢? 在交通工具商店中加一个if else判断如 ...
- 【收藏】Linux添加/删除用户和用户组
1.建用户: adduser phpq //新建phpq用户 passwd phpq ...
- CSS3图片旋转特效
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- 【Same Tree】cpp
题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...
- UVALive - 7374 Racing Gems 二维非递减子序列
题目链接: http://acm.hust.edu.cn/vjudge/problem/356795 Racing Gems Time Limit: 3000MS 问题描述 You are playi ...
- 以前用过Extjs技术的开发人员在学习Extjs4时需要注意的问题
以前学习过Extjs的同学,在学习Extjs4的时候需要注意几个关键改变: 1.Extjs4的新的类系统. 2.Extjs4中MVC思路 3.Extjs4中的新的命名规范(结合新的MV ...