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.
00
00
1
00X00X0XXX0
0XXX0X00X00
4
0X0X0
0X0X0
0
0XXX0
00000
2
题意: 给你两个串字符串,0是空地,x是墙,问这两串字符串可以容纳多少个L,L可以倒置
直接贪心,遍历一次,如果此次竖着两个为0,则再加一个0就能凑成L,从前后找L,找到就加一,记得找到后将已经找到的置为x(开始竖着的没有置为‘x’wa了一发)
#include <map> #include <set> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <cstring> #include <iostream> #include <algorithm> #define debug(a) cout << #a << " " << a << endl using namespace std; const int maxn = 1e6 + 10; const int mod = 1e9 + 7; typedef long long ll; int main(){ std::ios::sync_with_stdio(false); string s1, s2; while( cin >> s1 >> s2 ) { bool flag = false; ll num = 0; for( ll i = 0; i < s1.length(); i ++ ) { if( s1[i] == s2[i] && s1[i] == '0' ) { flag = true; } if( flag ) { if( i > 0 ) { if( s1[i-1] == '0' || s2[i-1] == '0' ) { s1[i] = 'x', s2[i] = 'x'; num ++, flag = false; } } if( i < s1.length() - 1 ) { if( s1[i+1] == '0' && flag ) { s1[i] = 'x', s2[i] = 'x', s1[i+1] = 'x'; num ++, flag = false; } if( s2[i+1] == '0' && flag ) { s1[i] = 'x', s2[i] = 'x', s2[i+1] = 'x'; num ++; } } flag = false; } //debug(i), debug(num); } cout << num << endl; } return 0; }