Hrbust 2320 OX (博弈)
题目链接 Hrbust 2320
用三进制来存储整个棋盘的状态。
设$dp[status][now]$为轮到$now$下棋的时候是必胜必败还是平局。
那么若当前能延伸出的所有状态中存在必败态的,则当前状态为必胜态。
否则看所有延伸出的所有状态中是否存在一个平局态,如果存在则当前状态为平局。
否则当前状态为必败态。
平局局面:当棋盘已经被下满并且没有任意$3$个棋子连起来的时候则平局。
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) const int N = 2e4 + 10;
const char *sss = ".ox~"; int a[3][3];
int f[N][2];
char ch[2];
int T;
int s, x;
int ans; int calc(int a[3][3]){
int ret = 0;
rep(i, 0, 2){
rep(j, 0, 2){
ret = ret * 3 + a[i][j];
}
} return ret;
} int solve(int s, int x){
if (~f[s][x]) return f[s][x];
int c[3][3];
memset(c, 0, sizeof c); int xx = s;
dec(i, 2, 0){ dec(j, 2, 0){ c[i][j] = xx % 3; xx /= 3; }} if (c[0][0] && c[0][0] == c[0][1] && c[0][1] == c[0][2] && c[0][0] != x) return f[s][x] = 1;
if (c[1][0] && c[1][0] == c[1][1] && c[1][1] == c[1][2] && c[1][0] != x) return f[s][x] = 1;
if (c[2][0] && c[2][0] == c[2][1] && c[2][1] == c[2][2] && c[2][0] != x) return f[s][x] = 1;
if (c[0][0] && c[0][0] == c[1][0] && c[1][0] == c[2][0] && c[2][0] != x) return f[s][x] = 1;
if (c[0][1] && c[0][1] == c[1][1] && c[1][1] == c[2][1] && c[2][1] != x) return f[s][x] = 1;
if (c[0][2] && c[0][2] == c[1][2] && c[1][2] == c[2][2] && c[2][2] != x) return f[s][x] = 1;
if (c[0][0] && c[0][0] == c[1][1] && c[1][1] == c[2][2] && c[0][0] != x) return f[s][x] = 1;
if (c[0][2] && c[0][2] == c[1][1] && c[1][1] == c[2][0] && c[0][2] != x) return f[s][x] = 1; int yy = 0;
rep(i, 0, 2) rep(j, 0, 2) if (c[i][j] == 0) yy = 1;
if (!yy) return f[s][x] = 0; int ff[11];
memset(ff, 0, sizeof ff);
int cnt = 0;
rep(i, 0, 2){
rep(j, 0, 2){
if (c[i][j]) continue;
c[i][j] = x;
int ss = calc(c);
++cnt;
ff[cnt] = solve(ss, 3 - x);
c[i][j] = 0;
}
} int ret0 = 0, ret2 = 0;
rep(i, 1, cnt){
if (ff[i] == 1) ret2 = 1;
else if (ff[i] == 0) ret0 = 1;
} if (ret2) return f[s][x] = 2;
else if (ret0) return f[s][x] = 0;
else return f[s][x] = 1;
} void init(){
rep(i, 0, 2){
rep(j, 0, 2){
scanf("%s", ch);
if (ch[0] == '.') a[i][j] = 0;
else if (ch[0] == 'o') a[i][j] = 1;
else if (ch[0] == 'x') a[i][j] = 2;
}
} scanf("%s", ch);
if (ch[0] == 'o') x = 1;
else x = 2;
s = calc(a);
} int main(){ memset(f, -1, sizeof f); scanf("%d", &T);
while (T--){
init();
ans = solve(s, x);
if (x == 2){
if (ans == 2) puts("x win!");
else if (ans == 1) puts("o win!");
else puts("tie!");
} else{
if (ans == 2) puts("o win!");
else if (ans == 1) puts("x win!");
else puts("tie!");
}
} return 0;
}
Hrbust 2320 OX (博弈)的更多相关文章
- 【迭代博弈+搜索+剪枝】poj-1568--Find the Winning Move
poj 1568:Find the Winning Move [迭代博弈+搜索+剪枝] 题面省略... Input The input contains one or more test cas ...
- hdu----(1849)Rabbit and Grass(简单的尼姆博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5754 Life Winner Bo 组合博弈
Life Winner Bo Problem Description Bo is a "Life Winner".He likes playing chessboard gam ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- 51nod1072(wythoff 博弈)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1072 题意: 中文题诶~ 思路: 博弈套路是有的, 找np局 ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- 【转】ACM博弈知识汇总
博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...
- Uva 10891 经典博弈区间DP
经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能 ...
随机推荐
- python之时间处理time模块
import time import datetime ''' print(time.time()) #返回当前系统时间戳 print(time.ctime()) #返回当前系统时间 print(ti ...
- Kali 中文家目录改英文目录
中文版Kali装好之后,家目录会中文显示,不便操作 root@kali:~# ls -l drwxr-xr-x root root .0K 7月 : 公共 drwxr-xr-x root root . ...
- HDU 3368 Reversi
http://acm.hdu.edu.cn/showproblem.php?pid=3368 题意:模拟黑白棋,下一步黑手最大可以转化多少个白旗 分析:暴力 原先的思路是找到D然后遍历其八个方向,直到 ...
- 2 Model层 -定义模型
1 ORM简介 MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库 ORM是“对象-关系-映射” ...
- Proguard returned with error code 1. See console
满世界的bug. 微信支付,Windows的远程桌面. Android的 , Proguard returned with error code 1. See console解决办法" 真的 ...
- Python虚拟机类机制之绑定方法和非绑定方法(七)
Bound Method和Unbound Method 在Python中,当对作为属性的函数进行引用时,会有两种形式,一种称为Bound Method,这种形式是通过类的实例对象进行属性引用,而另一种 ...
- mysql之面试问题总结
问题1.char 与varchar的区别? varchar是变长而char的长度是固定的.如果你的内容是固定的大小,char性能更好. char[4] 与varchar[4] 存储字母a a占一个 ...
- hdu3366 Count the string
考虑dp[i]代表前缀s[1...i]出现的次数,必定有dp[nxt[i]] += dp[i] 倒着推就是了 #include <iostream> #include <cstrin ...
- 步骤详解安装Apache web服务器
1.在上右键è安装 安装后apache web服务器自动启动. 在右下角出现. Apache安装之后有一个默认的网站目录 在浏览器上通过网站就可以访问到该目录下的文件. 2.测试 在浏览器输上请求lo ...
- 33、Android Support兼容包详解(转载)
原文转自:微信分享 2015-03-31 22:11 背景 来自于知乎上邀请回答的一个问题Android中AppCompat和Holo的一个问题?, 看来很多人还是对这些兼容包搞不清楚,那么干脆写篇博 ...