UVa10111 - Find the Winning Move
2014-04-01 12:33
274 查看
Problem A: Find the Winning Move
Source file: | win.{c, cpp, java, pas} |
Input file: | win.in |
Output file: | win.out |
? .... .xo. .ox. .... ? o... .ox. .xxx xooo $Example output:
##### (0,1)
4子棋,DP可以搞定+回溯
#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <string>using namespace std;char mat[4][4];int nowx();bool nowo();char check(){for(int i = 0; i < 4; i++){if(mat[i][0] != '.' ){bool flag = 0;for(int j = 0; j < 3; j++){if(mat[i][j] != mat[i][j+1]){flag = 1;break;}}if(!flag) return mat[i][0];}}for(int i = 0; i < 4; i++){if(mat[0][i] != '.' ){bool flag = 0;for(int j = 0; j < 3; j++){if(mat[j][i] != mat[j+1][i]){flag = 1;break;}}if(!flag) return mat[0][i];}}if(mat[0][0] != '.'){bool flag = 0;for(int i = 0; i < 3; i++){if(mat[i][i] != mat[i+1][i+1]){flag = 1;break;}}if(!flag) return mat[0][0];}if(mat[3][0] != '.'){if(mat[3][0]== mat[2][1] && mat[2][1] == mat[1][2] && mat[1][2] ==mat[0][3])return mat[3][0];}return 0;}bool nowo(){for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++){if(mat[i][j] == '.'){mat[i][j] = 'o';if(check()=='o'|| nowx()<0){mat[i][j] = '.';return 1;}mat[i][j] = '.';}}return 0;}int nowx(){for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++){if(mat[i][j] == '.'){mat[i][j] = 'x';if(check() == 'x' || !nowo()){mat[i][j] = '.';return i<<8|j;}mat[i][j] = '.';}}return -1;}int main(){char t;while(cin >> t && t != '$'){for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++)cin >> mat[i][j];int ans = nowx();if(ans==-1){cout<<"#####"<<endl;}else{printf("(%d,%d)\n",ans >> 8 ,ans&0xff);}}return 0;}[/code]
相关文章推荐
- poj1568 Find the Winning Move[极大极小搜索+alpha-beta剪枝]
- poj1568 Find the Winning Move
- poj 1568 Find the Winning Move 极大极小搜索
- poj 1085 Triangle War 1568 Find the Winning Move 极大极小搜索 alpha-beta剪枝
- 博弈(alpha-beta 剪枝)—— POJ 1568 Find the Winning Move
- POJ 1568 Find the Winning Move(极大极小搜索)
- [POJ1568]Find the Winning Move(极大极小搜索,alpha-beta剪枝,特判)
- 【poj1568】 Find the Winning Move
- 【POJ1568】【极大极小搜索+alpha-beta剪枝】Find the Winning Move
- poj1568 Find the Winning Move
- POJ 1568 Find the Winning Move(极小极大搜索+alpha-beta剪枝)
- POJ 1568 Find the Winning Move(极大极小搜索+alpha-beta剪枝)
- POJ 1568 Find the Winning Move 极大极小搜索+alpha-beta剪枝 -
- POJ 1568 Find the Winning Move
- Poj1568 Find the Winning Move(极大极小搜索)
- pku1568 Find the Winning Move 完全极大极小搜索
- CareerCup Find out the winning probability given n, m and x
- poj 1734 Sightseeing trip hdu 1599 find the mincost route 最小环 解题报告
- 转:could not find the main class, Program will exit (说明编译器compiler版本要不高于installed JREs,JVM版本)
- 1435: Find the minimum