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.
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 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
#include<algorithm>
#include<iostream>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define maxn 103
#define ll long long
#define INF 10000000
using namespace std;
char c1[maxn],c2[maxn];
int judge(int t)
{
if('X'==c1[t])
{
if(c2[t]=='X') return 0;
else return 1;
}
else
{
if(c2[t]=='X') return 2;
else return 3;
}
}
/*
题目大意:我也是看图猜出来的,,读题太仔细反而乱了思路。。
就是填L形方块的问题,,给一个二排序列字符看最多能放多少个。。
简单的dp问题,,唯一需要注意的细节是三个连续为空时的特判,,,三个连续单独看成了一个状态了。。。
*/
int main()
{
scanf("%s",c1+1);
scanf("%s",c2+1);
c1[0]='X',c2[0]='X';
int n=strlen(c1+1),dp[maxn];
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
dp[i]=dp[i-1];
int sta=judge(i);
if(sta==1||sta==2)
{
if(judge(i-1)==3) dp[i]=max(dp[i],dp[i-2]+1);
}
else if(sta==3)
{
int tp=judge(i-1);
if(tp) dp[i]=max(dp[i-2]+1,dp[i]);
if(tp==3&&judge(i-2)==3) dp[i]=max(dp[i],dp[i-3]+2);
}
}
printf("%d\n",dp[n]);
return 0;
}