zoukankan      html  css  js  c++  java
  • 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;
    }
    彼时当年少,莫负好时光。
  • 相关阅读:
    JS中怎样获取当前日期的前一个月和后一个月的日期字符串
    JS中怎样将时间字符串转换成Date并比较大小
    Java中判断两个Date时间段是否有交集的方法
    gRPC中Java和node进行异构通信-互为客户端和服务端
    ffmpeg external libraries 下载地址
    libsvtav1 的 qp 和比特率对照表
    libsvtav1 AV1 编码速度比 libaom 大大提升
    ffmpeg windows 最新编译内部版本下载地址变更
    解开获取 aria2c 帮助信息的误区
    frei0r 过了好几年增加 aech0r 滤镜
  • 原文地址:https://www.cnblogs.com/l609929321/p/9230854.html
Copyright © 2011-2022 走看看