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
题意:
就是给你一个2xn的棋盘,其中为0的表示可以放棋子,但是依次放的棋子必须的3个在一起成一定形状
XX XX .X X.
X. .X XX XX
就想这样,问你能放多少个
思路:这道题可以用dp来写,但是如果用dp来写的话,会变麻烦,不如直接贪心
对于第i列的数,如果它只能和i+1列或i-1列成图形,所以一个pre记录前面的可放空格,now记录现在的可放空格,一旦大于3,那就可以进行操作并且ans++
//
// main.cpp
// Bishwock
//
// Created by dhl on 2018/7/20.
// Copyright © 2018年 dhl. All rights reserved.
//
#include
#include
#include
using namespace std;
string a , b;
int main(int argc, const char * argv[]) {
cin >> a >> b;
int now = 0, pre = 0, ans = 0;
for (int i = 0; i < a.length(); i ++){
now = (a[i] == '0') + (b[i] == '0');
if (now == 1) {
if (pre == 2){
ans ++;
pre = 0;
}else if (pre == 0) {
pre = 1;
}
}else if (now == 2) {
if (pre == 1) {
ans ++;
pre = 0;
}else if (pre == 2) {
ans ++;
pre = 1;
}else {
pre = 2;
}
}else if (now == 0) {
pre = 0;
}
}
cout << ans << endl;
return 0;
}