Codeforces Round #736 (Div. 2)_B. Gregor and the Pawn Game

B. Gregor and the Pawn Game

题目传送门:

题目传送门!

题面:

在这里插入图片描述

题目大意:

你的棋子在最后一排,对方的棋子在第一排。
给你两个字符串用01表示有无棋子在上面。

走法:

  1. 往上走,要求是上方无棋子阻挡;
  2. 斜对角走一格,要求是目的格子上只有一个敌方棋子。

问你有几个棋子能走到第一排。
只有你的棋子可以动。

思路:

直接暴力模拟。
对你的棋子是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;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值