随笔—邀请赛前训—Codeforces Round #328 (Div. 2) A. PawnChess
Posted Shawn_Ji
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了随笔—邀请赛前训—Codeforces Round #328 (Div. 2) A. PawnChess相关的知识,希望对你有一定的参考价值。
题意:给你一个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; }
以上是关于随笔—邀请赛前训—Codeforces Round #328 (Div. 2) A. PawnChess的主要内容,如果未能解决你的问题,请参考以下文章
随笔—邀请赛前训— Codeforces Round #330 (Div. 2) Vitaly and Night
随笔—邀请赛前训—Codeforces Round #330 (Div. 2) B题
随笔—邀请赛前训—Duff and Weight Lifting