B. Gregor and the Pawn Game
题目传送门:
题面:
题目大意:
你的棋子在最后一排,对方的棋子在第一排。
给你两个字符串用01表示有无棋子在上面。
走法:
- 往上走,要求是上方无棋子阻挡;
- 斜对角走一格,要求是目的格子上只有一个敌方棋子。
问你有几个棋子能走到第一排。
只有你的棋子可以动。
思路:
直接暴力模拟。
对你的棋子是0的部分开始,如果对着的部分是1:那么找斜角线有无1;
如果对着的部分是0,那么直接走进去就完事了。
用过的格子不能重复使用,记得处理一下。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string str1, str2;
int main() {
int T;
cin >> T;
while (T--) {
int cnt = 0;
vector<int> v1;
int n;
cin >> n;
cin >> str1;
cin >> str2;
for (int i = 0; i < n; i++)
if (str2[i] == '1') v1.push_back(i);
for (int i = 0; i < v1.size(); i++) {
// cout<<str1[v1[i]]<<" "<<str2[v1[i]]<<endl;
if (str1[v1[i]] == '0') cnt++;
else if (v1[i] == 0) {
if (str1[v1[i] + 1] == '1') cnt++, str1[v1[i] + 1] = '2';
} else if ((str1[v1[i] - 1] == '1') || str1[v1[i] + 1] == '1') {
cnt++;
if (str1[v1[i] - 1] == '1') {
str1[v1[i] - 1] = '2';
} else {
str1[v1[i] + 1] = '2';
}
}
}
cout << cnt << endl;
}
}