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;
    }
    彼时当年少,莫负好时光。
  • 相关阅读:
    在eclipse中快速多行注释的方法
    Android开发:去掉Activity的头部标题栏及全屏显示
    C#的Process类的一些用法
    C#中隐式操作CMD命令行窗口 (转)
    我的INI 配置文件读写动态库
    Android高手进阶教程(五)之----Android 中LayoutInflater的使用!
    Android高手进阶教程(六)之----Android 中MenuInflater的使用(布局定义菜单)!
    Android Menu 之 optionsMenu 详解
    centos安装php扩展
    linux 权限
  • 原文地址:https://www.cnblogs.com/l609929321/p/9230854.html
Copyright © 2011-2022 走看看