Circle vs Triangle(DFS+博弈)
来源:互联网 发布:无用神力兄弟会 知乎 编辑:程序博客网 时间:2024/05/22 02:41
B - Circle vs Triangle
Problem Description
Alice and Bob invent a new game called "circle vs triangle". At first there are a rectangle map, which consists of n*m unit-squares. Then lady first. Alice can choose any unit square and write a circle in it. And then Bob choose a unit square which next to the one that Alice just choose, and write a triangle in it. Turning to Alice again. Each player should choose a unit square which next to the one that another one chooses, and write a shape standing for him or her.
However, Alice and Bob find such silly game is so boring. Then they let some square in the map become barriers, which means these square can't be written anything on it.
So, give you a map, please tell me who can win or it can lead to a draw, if both Alice and Bob make a optimal choice.
Input
Then an n*m map is shown. Please read the sample to get more informations.
Output
Otherwise, please output the name of player who can win if both make optimal choice.
Sample Input
3 3******...3 3*****....
Sample Output
AliceBob
Hint
For the second case, Bob will win in the end wherever Alice choose firstly.
题目大意:在一个棋盘上,Alice和Bob两人轮流放棋子,Alice先手,问Alice是否必胜
分析:首先介绍一下博弈的思想。
对于1VS1的棋类游戏而言,如果这一步我有必胜策略,那我就可以必胜;如果无论我这一步怎么操作,对方都有必胜策略,那么我就必败。注意前一句的条件是“存在”,后一句是“任意”。这两句话构成了博弈论的基石。
然后,就可以DFS搜是否存在必胜策略即可。
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct Node { int x, y;}node[40];int n, m;char mp[10][10];int vis[10][10];int dx[4] = {0, 1, 0, -1};int dy[4] = {1, 0, -1, 0};bool dfs(int x, int y) { int flag = 0; for(int i = 0; i < 4; i++) { int tx = x+dx[i]; int ty = y+dy[i]; if(tx < 0 || tx >= n || ty < 0 || ty >= m || mp[tx][ty] == '*' || vis[tx][ty]) continue; vis[tx][ty] = 1; if(dfs(tx, ty)) { flag = 1; break; } vis[tx][ty] = 0; } if(flag) return 0; else return 1;}int main() { while(~scanf("%d%d", &n, &m)) { int cnt = 0; for(int i = 0; i < n; i++) { scanf("%s", mp[i]); for(int j = 0; j < m; j++) { if(mp[i][j] == '.') { node[cnt].x = i; node[cnt++].y = j; } } } memset(vis, 0, sizeof(vis)); int flag = 0; for(int i = 0; i < cnt; i++) { int tx = node[i].x, ty = node[i].y; vis[tx][ty] = 1; if(dfs(tx, ty)) { flag = 1; break; } vis[tx][ty] = 0; } if(flag) printf("Alice\n"); else printf("Bob\n"); } return 0;}
- Circle vs Triangle(DFS+博弈)
- ACDREAM 05B Circle vs Triangle(DFS专场)
- HZAU 1208 Color Circle (dfs)
- HZAU1208——Color Circle(dfs)
- POJ 2986 A Triangle and a Circle(计算几何)
- HDOJ 题目3964 Find The Simple Circle(DFS)
- hdu 1536 博弈 SG函数(dfs)
- Problem J: Color Circle----dfs
- POJ 1085 Triangle War(博弈,極大極小搜索+alpha_beta剪枝)
- POJ 2986 A Triangle and a Circle
- Leetcode dfs&dp Triangle
- POJ1163 The Triangle【DFS】
- 【dfs博弈】HDU 4155
- [HDU 4324] Triangle LOVE (拓扑排序,DFS)
- 第十四周 项目二:定义抽象类Shape,由此派生出Circle(圆形)、Rectangle(矩形)、Triangle(三角形)
- 十三周(三)定义抽象类shape,由它派生出三个派生类Circle,Rectangle,Triangle
- 山东省第六届ACM省赛题——Circle of Friends(强连通分量+dfs)
- HDU 4324 CODE[VS] 2066 triangle love(拓扑排序)
- c++的构造函数与析构函数区别和使用析构函数的注意事项g
- UC/OS II 任务管理(5)之任务删除、阻塞和恢复
- 自学QT之实现一个用户信息窗口
- js window.open 打开页面并居中
- 文法相关
- Circle vs Triangle(DFS+博弈)
- java练习:金额转换,阿拉伯数字转换成中文传统形式
- poj 2195 Going Home【zkw费用流】
- HDU 2222 Keywords Search(AC自动机)
- Linux中Tomcat 自动设置CATALINA_HOME方法
- scala (6)柯里化
- 自旋锁在内核中的实现
- 'sessionFactory' or 'hibernateTemplate' is required
- 2.1.4 Shading in World Space (about uniforms) 在世界坐标系里着色(关于uniforms参数)