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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值