翻翻棋
来源:互联网 发布:手机怎么设置网络优先 编辑:程序博客网 时间:2024/04/29 11:57
象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将。根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃掉对方的棋子。将和帅为同一级别。然而胜负在只剩下帅和将的时候已定。
第一行T,表示T组数据。
每组数据共有四行字符串,每行字符串共八个字符
’#’表示空格
’*’表示红方帅
’.’表示黑方将
此时红方先走
每组输入之间没有空行。
每组数据输出一行。若为红方赢输出Red win,否则输出 Black win
1######.######*##################
Black win
和同学找了好久的规律,如果两者距离为偶数,则为黑赢,反之红赢。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int vis[4][2]= {{-1,0},{0,1},{1,0},{0,-1}};int tx,ty,p,q;char map[10][10];int book[10][10];int sum;struct node{ int x,y,s;};void bfs(){ queue<node>que; struct node pe,pr; pe.x=tx; pe.y=ty; pe.s=0; que.push(pe); int i,j; while(!que.empty()) { pr=que.front(); que.pop(); for(i=0 ; i<4; i++) { int xx=pr.x+vis[i][0]; int yy=pr.y+vis[i][1]; if(xx<0||xx>=4||yy<0||yy>=8) { continue; } if(book[xx][yy]==0) { pe.x=xx; pe.y=yy; pe.s=pr.s+1; que.push(pe); book[xx][yy]=1; } if(pr.x==p&&pr.y==q) { sum=pr.s; if(sum%2==0) { printf("Black win\n"); } else { printf("Red win\n"); } return ; } } }}int main(){ int n,m,i,j; scanf("%d",&n); while(n--) { int sum=0; memset(book,0,sizeof(book)); for(i=0; i<4; i++) { scanf("%s",map[i]); } for(i=0; i<4; i++) { for(j=0; j<8; j++) { if(map[i][j]=='*') { tx=i; ty=j; } if(map[i][j]=='.') { p=i; q=j; } } } bfs(); //printf("%d\n",sum); } return 0;}
阅读全文
0 0
- 翻翻棋
- 翻翻棋
- 翻翻棋
- FZU 2230 翻翻棋
- FZU 翻翻棋
- FZU 2230 翻翻棋
- 翻翻
- FZU Problem 2230 翻翻棋
- FZU 2230 翻翻棋 (找规律 水题)
- FZU-2230 翻翻棋(博弈论,规律题)
- 福州大学第十三届程序设计竞赛 Problem B 翻翻棋【bfs】
- FZU 2230 2230 翻翻棋(思维水题)
- 翻翻翻
- 随便翻翻《程序员》
- 翻翻股推荐黑马
- 3076 翻翻乐
- 有时间翻翻这些书
- 回家较早,翻翻c++primer
- 1003.我要通过!
- LintCode_491_回文数
- Android中运用OpenGL
- 9.Lua调用c++函数获取返回值
- 根据不同的值给父级div添加class样式
- 翻翻棋
- 甲骨文武国平高吉戠至模组:命令(其六)
- I
- 10.c++给lua传递变量和访问Lua的全局变量
- 连续最大和
- HistCite 的使用方法
- hdu_1398_Square Coins(母函数)
- 食物链 POJ
- HDU6178