1 条题解
-
0梦萦枯野 LV 8 @ 2019-01-01 15:09:03
比较复杂的模拟。
#include<iostream> #include<vector> using namespace std; int N,M,gap; vector<char> board; void swap(int,int); bool onboard(int); int main() { cin>>N>>M; board.resize(2*N+1+1); board[N+1]='S';gap=N+1; for (int i=1;i<=N;i++) board[i]='W'; for (int i=2+N;i<=2*N+1;i++) board[i]='B'; for (int i=1;i<=M;i++) { /*check if can jump*/ /*check W jump*/ if (onboard(gap-2)&&board[gap-2]=='W'&&board[gap-1]=='B'){ swap(gap,gap-2);continue; } /*check B jump*/ if (onboard(gap+2)&&board[gap+2]=='B'&&board[gap+1]=='W'){ swap(gap,gap+2);continue; } /*check if can make same*/ /*W*/ if (onboard(gap-1)&&onboard(gap-2)&& board[gap-1]=='W'&&board[gap-2]=='W'){ swap(gap,gap-1);continue; } /*B*/ if (onboard(gap+1)&&onboard(gap+2)&& board[gap+1]=='B'&&board[gap+2]=='B'){ swap(gap,gap+1);continue; } /*else,just move one*/ if (onboard(gap-1)&&board[gap-1]=='W') swap(gap,gap-1); else swap(gap,gap+1); } for (int i=1;i<=2*N+1;i++) cout<<board[i]; return 0; } void swap(int g,int b) { gap=b; board[g]=board[b]; board[b]='S'; } /*check is the position on board*/ bool onboard(int pos) { return (pos>=1&&pos<=2*N+1); }
- 1
信息
- 难度
- 9
- 分类
- (无)
- 标签
- 递交数
- 6
- 已通过
- 5
- 通过率
- 83%
- 上传者