题意:给你一个8×8的棋盘分布,红黑棋子,双方只能朝上下其中一个方向移动,不可跨越对方或自己的棋子,最先到对面底部的人赢。问谁赢?
思路:上下2排同时开始扫,先扫到谁都棋,谁就赢(前提是没有对方的人挡路。。)
#include<cstdio> #include<cstring> #include<iostream> using namespace std; #define MAX(x,y) (((x)>(y)) ? (x) : (y)) #define MIN(x,y) (((x) < (y)) ? (x) : (y)) #define ABS(x) ((x)>0?(x):-(x)) const int inf = 0x7fffffff; int occupied_by_black[10]; int occupied_by_white[10]; char mp[10][10]; int main() { char winer='*'; for(int i=1; i<=8; i++){ scanf("%s",mp[i]+1); } for(int i=1; i<=8; i++){ int p_for_white=i; int p_for_black=8-i+1; for(int j=1;j<=8;j++){ if(mp[p_for_white][j] == 'B') occupied_by_black[j]=1; if(mp[p_for_white][j] == 'W' && occupied_by_black [j] == 0){ occupied_by_white[j]=1; winer='A'; break; } } if(winer != '*') break; for(int j=1; j<=8; j++){ if(mp[p_for_black][j] == 'W') occupied_by_white[j]=1; if(mp[p_for_black][j] == 'B' && occupied_by_white [j] == 0){ occupied_by_black[j]=1; winer='B'; break; } } if(winer != '*') break; } cout<<winer<<endl; return 0; }