HDU 4155 The Game of 31 (博弈)
来源:互联网 发布:淘宝商业计划书模板 编辑:程序博客网 时间:2024/05/20 00:50
题意:
1,2,3,4,5,6各有4张一共24张牌,2个人拿牌,要求牌的总和不能超过31,超过了不能拿,谁不能拿谁输
分析:
博弈基本思想:
当前是必胜态,当且仅当有一个后继是必败态
当前是必败态,当且仅当所有后继是必胜态
没有后继的是必败态
其实第一个拿到31的是必胜态,写的时候反过来看起来跑得快
代码:
//// Created by TaoSama on 2015-11-21// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int card[10];char s[20];bool dfs(int sum) { if(sum == 31) return false; for(int i = 1; i <= 6; ++i) { if(sum + i > 31) break; if(!card[i]) continue; --card[i]; bool F = dfs(sum + i); ++card[i]; if(!F) return true; } return false;}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(scanf("%s", s) == 1) { for(int i = 1; i <= 6; ++i) card[i] = 4; int sum = 0; int n = strlen(s); for(int i = 0; i < n; ++i) { --card[s[i] - '0']; sum += s[i] - '0'; } printf("%s ", s); //这里必败和必胜反过来了 if(dfs(sum)) printf("%c\n", "AB"[n & 1]); //必败 else printf("%c\n", "BA"[n & 1]); //必胜 } return 0;}
0 0
- HDU 4155 The Game of 31 (博弈)
- The Game of 31 (博弈)
- HDOJ 4155 The Game of 31 博弈搜索
- hdu 4155 The Game of 31
- 【记忆化搜索】 HDU-4155-The Game of 31
- ECPC16-A.The game of Osho(博弈)
- HDU 4023 Game (博弈)
- HDU 3389 Game(博弈)
- hdu 4701 Game(博弈)
- URAL 2068 Game of Nuts(博弈)
- URAL2068:Game of Nuts(博弈)
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- Codeforces 549C. The Game Of Parity 博弈
- codeforces 549C C. The Game Of Parity(博弈)
- Codeforces 549C The Game Of Parity【博弈】
- HDU-5973-Game of Taking Stones(JAVA-BigDecimal+Wythoff博弈)
- HDU 5973-Game of Taking Stones(威佐夫博弈-JAVA BigDecimal)
- HDU 5973 Game of Taking Stones 博弈+高精度
- HDU 2242 考研路茫茫 空调教室(tarjan bcc + tree dp)
- poj 2063 Investment
- 阿里云服务器配置说明(待完善)
- C# 获取获取经纬度!
- POJ 3694Network (tarjan bcc + LCA)
- HDU 4155 The Game of 31 (博弈)
- 字节流与字符流的区别详解
- HDU 1536 S-Nim(组合游戏Nim)
- 在WPS中粘帖代码保持代码高亮
- 垃圾回收的一些面试题
- 计算机的存储介质介绍
- 标准trie树(前缀树)的介绍及java实现
- Trie 树 及Java实现
- Unity中使用SLua的一些注意事项