Codeforces 991D Bishwock (模拟)

版权声明:希望我的博客可以为别人带去知识与便利,让那些像我曾经一样迷茫的小伙伴不再迷茫~ https://blog.csdn.net/qq_34374664/article/details/80939313


D. Bishwock
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:

XX   XX   .X   X.
X.   .X   XX   XX

Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.

Vasya has a board with 2×n2×n squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully.

Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns.

Input

The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed 100100.

Output

Output a single integer — the maximum amount of bishwocks that can be placed onto the given board.

Examples
input
Copy
00
00
output
Copy
1
input
Copy
00X00X0XXX0
0XXX0X00X00
output
Copy
4
input
Copy
0X0X0
0X0X0
output
Copy
0
input
Copy
0XXX0
00000
output
Copy
2

题意:给出2*n的矩阵,0可放,X不可放,问能放多少个L形,L可旋转。

思路:从左往右遍历, 遇到一列都是0的 贪心的先往左放,再往右放,类似开关问题

#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + 5;
char str[2][maxn];
int main()
{
    int t;
    scanf("%s", str[0]);
    scanf("%s", str[1]);
    int len = strlen(str[0]);
    int ans = 0;
    for(int i = 0; i < len; i++)
    {
        if(str[0][i] == '0' && str[1][i] == '0')
        {
            if(i-1 >= 0 && str[0][i-1] == '0')
            {
                str[0][i-1] = 'X';
                str[0][i] = 'X';
                str[1][i] = 'X';
                ans++;
            }
            else if(i-1 >= 0 && str[1][i-1] == '0')
            {
                str[1][i-1] = 'X';
                str[0][i] = 'X';
                str[1][i] = 'X';
                ans++;
            }
            else if(str[0][i+1] == '0')
            {
                str[0][i+1] = 'X';
                str[0][i] = 'X';
                str[1][i] = 'X';
                ans++;
            }
            else if(str[1][i+1] == '0')
            {
                str[1][i+1] = 'X';
                str[0][i] = 'X';
                str[1][i] = 'X';
                ans++;
            }
//            cout << i << ' ' <<ans << endl;
        }
    }
    printf("%d\n", ans);
    return 0;
}


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页