UVA 11534 - Say Goodbye to Tic-Tac-Toe(博弈sg函数)
来源:互联网 发布:软件外包服务商排名 编辑:程序博客网 时间:2024/05/22 01:45
UVA 11534 - Say Goodbye to Tic-Tac-Toe
题目链接
题意:给定一个序列,轮流放XO,要求不能有连续的XX或OO,最后一个放的人赢,问谁赢
思路:sg函数,每一段...看成一个子游戏,利用记忆化求sg值,记忆化的状态要记录下左边和右边是X还是O即可
代码:
#include <stdio.h>#include <string.h>const int N = 105;int t, sg[3][3][N];char str[N];int getnum(char c) {if (c == 'X') return 1; if (c == 'O') return 2;}int mex(int s, int e, int l) {if (sg[s][e][l] != -1) return sg[s][e][l];if (l == 0) return sg[s][e][l] = 0;bool vis[N];memset(vis, false, sizeof(vis));for (int i = 1; i <= l; i++) {for (int j = 1; j <= 2; j++) {if (i == 1 && s == j) continue;if (i == l && e == j) continue;int t = mex(s, j, i - 1)^mex(j, e, l - i);vis[t] = true; } } for (int i = 0; ;i++) if (!vis[i]) return sg[s][e][l] = i;}int main() {memset(sg, -1, sizeof(sg));scanf("%d", &t);while (t--) {scanf("%s", str);int len = strlen(str), s = 0, e = 0, l = 0, ans = 0, cnt = 0;for (int i = 0; i < len; i++) {if (str[i] == '.')l++;else {e = getnum(str[i]);ans ^= mex(s, e, l);s = e; l = 0; cnt++; } } ans ^= mex(s, 0, l); if (cnt&1) ans = (ans == 0?1:0); printf("%s\n", ans?"Possible.":"Impossible.");}return 0;}
1 0
- UVA 11534 - Say Goodbye to Tic-Tac-Toe(博弈sg函数)
- uva 11534 - Say Goodbye to Tic-Tac-Toe(Nim和)
- 【Light OJ】No More Tic-tac-toe (博弈 SG函数)
- UVa 10363 - Tic Tac Toe
- 机器博弈:tic-tac-toe游戏
- sgu289:Challenging Tic-Tac-Toe(博弈搜索)
- 【FZUoj 2283 Tic-Tac-Toe】& dfs & 博弈
- uva 11623 - Tic Tac Toe(game)
- Tic-Tac-Toe
- [cf]Tic-tac-toe
- C - Tic-tac-toe
- Minimax-Tic Tac Toe
- Design Tic-Tac-Toe
- Design Tic-Tac-Toe
- Design Tic-Tac-Toe
- FZU Tic-Tac-Toe
- Tic-Tac-Toe FZU
- FZU2283-Tic-Tac-Toe
- [cocos2dx lua]cocos2dx lua入门
- 关于cocos2dx Box2D setBullet android 安卓 上面 卡的问题!!!!
- 窗口移动、改变大小的有关消息
- 最大匹配分词切分错误分类
- 绘图与动画学习笔记(一)
- UVA 11534 - Say Goodbye to Tic-Tac-Toe(博弈sg函数)
- android模拟器 报错:X Error of failed request: BadRequest (invalid request code or no such operation)
- Dbconsole 中 dbsnmp账户被锁后的处理
- 字符串 下
- java switch语句详解
- Lake Counting
- 黑马程序员_java基础篇之集合框架
- Codeforces Beta Round #57 (Div. 2) E. Enemy is weak
- 娓娓道来c指针 (0)c语言的梦魇:c指针