D. Bishwock(思维)

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


Codeforces (c) Copyright 2010-2018 Mike Mirzayanov


题意:给出一个2×n的矩阵,0表示空位,x表示已经被占用了。如果你想占用一个空位,那么,必须是以这样的形式占用:

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

红色的x表示你占用的位置,即,你占用一个位置,还要额外以上述的形式占用两个位置。问,你最多可以占用多少个位置


思路:当你占用一个位置,那么有4种情况。for循环,然后判断满足上述任意一种情况的ans++。

#include "iostream"
#include "cstring"
using namespace std;
char ch1[105],ch2[105];
int main()
{
    int ans=0;
    cin>>ch1>>ch2;
    int len=strlen(ch1);
    for(int i=0;i<len;i++){
        if(ch1[i]=='0'&&ch2[i]=='0'&&ch1[i+1]=='0') ch1[i]=ch1[i+1]=ch2[i]='x',ans++;
        else if(ch1[i]=='0'&&ch2[i]=='0'&&ch2[i+1]=='0') ch1[i]=ch2[i]=ch2[i+1]='x',ans++;
        else if(ch1[i]=='0'&&ch1[i+1]=='0'&&ch2[i+1]=='0') ch1[i]=ch1[i+1]=ch2[i+1]='x',ans++;
        else if(ch2[i]=='0'&&ch1[i+1]=='0'&&ch2[i+1]=='0') ch2[i]=ch1[i+1]=ch2[i+1]='x',ans++;
    }
    cout<<ans<<endl;
}


猜你喜欢

转载自blog.csdn.net/qq_41874469/article/details/80790774