• CF991D Bishwock 第十七 贪心


    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

    题意: 给你两个串字符串,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;
    }
    彼时当年少,莫负好时光。
  • 相关阅读:
    阿里云高级技术专家周晶:基于融合与协同的边缘云原生体系实践
    Spring Boot Serverless 实战系列“架构篇” 首发 | 光速入门函数计算
    基于 EMR OLAP 的开源实时数仓解决方案之 ClickHouse 事务实现
    【ClickHouse 技术系列】 在 ClickHouse 中处理实时更新
    LeetCode_Two Sum
    LeetCode_ Remove Element
    LeetCode_Same Tree
    LeetCode_Symmetric Tree
    LeetCode_Path Sum
    LeetCode_Merge Sorted Array
  • 原文地址:https://www.cnblogs.com/l609929321/p/9230854.html
Copyright © 2020-2023  润新知