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 + ;
const int mod = 1e9 + ;
typedef long long ll;
int main(){
std::ios::sync_with_stdio(false);
string s1, s2;
while( cin >> s1 >> s2 ) {
bool flag = false;
ll num = ;
for( ll i = ; i < s1.length(); i ++ ) {
if( s1[i] == s2[i] && s1[i] == '' ) {
flag = true;
}
if( flag ) {
if( i > ) {
if( s1[i-] == '' || s2[i-] == '' ) {
s1[i] = 'x', s2[i] = 'x';
num ++, flag = false;
}
}
if( i < s1.length() - ) {
if( s1[i+] == '' && flag ) {
s1[i] = 'x', s2[i] = 'x', s1[i+] = 'x';
num ++, flag = false;
}
if( s2[i+] == '' && flag ) {
s1[i] = 'x', s2[i] = 'x', s2[i+] = 'x';
num ++;
}
}
flag = false;
}
//debug(i), debug(num);
}
cout << num << endl;
}
return ;
}

CF991D Bishwock 第十七 贪心的更多相关文章

  1. CF991D Bishwock

    CF991D Bishwock 题目描述 给一个$2\times n$的网格,上面一些位置以及被覆盖上了.现在你有一种形状为L的小块,每个由三个小格组成,构成L型 现在问你,当前的网格最多还能摆多少小 ...

  2. G、CSL 的训练计划【BFS 贪心】(“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛)

    题目传送门:https://ac.nowcoder.com/acm/contest/551/G 链接:https://ac.nowcoder.com/acm/contest/551/G来源:牛客网 题 ...

  3. D、CSL 的字符串 【栈+贪心】 (“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛)

    题目传送门:https://ac.nowcoder.com/acm/contest/551#question 题目描述 CSL 以前不会字符串算法,经过一年的训练,他还是不会……于是他打算向你求助. ...

  4. “新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛(D题,贪心+栈)

    链接:https://ac.nowcoder.com/acm/contest/551/D来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言10485 ...

  5. 经典算法题每日演练——第十七题 Dijkstra算法

    原文:经典算法题每日演练--第十七题 Dijkstra算法 或许在生活中,经常会碰到针对某一个问题,在众多的限制条件下,如何去寻找一个最优解?可能大家想到了很多诸如“线性规划”,“动态规划” 这些经典 ...

  6. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  7. 我的MYSQL学习心得(十七) 复制

    我的MYSQL学习心得(十七) 复制 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  8. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. 传输层的TCP和UDP协议

    作者:HerryLo 原文永久链接: https://github.com/AttemptWeb... TCP/IP协议, 你一定常常听到,其中TCP(Transmission Control Pro ...

  2. Linux 常用命令及使用方法

    1.  type   :查询命令 是否属于shell解释器 2.  help  : 帮助命令3.  man : 为所有用户提供在线帮助4.  ls  : 列表显示目录内的文件及目录 -l    以长格 ...

  3. 算法实战-OJ之旅

    算法虽然不是特别简单,但没有你想象中的那么难. Sort Array By Parity easy AC-17ms. 按照<算法导论>排序一章的一些概念,第二种可以称为是原址的(in-pl ...

  4. redis高可用之DNS篇

    1.  背景 例如,存在一套redis主从(主从节点在不同的主机上),应用程序通过主库的ip进行读写操作. 但是,主库一旦出现故障,虽然有从库,且从库提升为主库,但是应用程序如果想使用从库则必须修改配 ...

  5. IntelliJ IDEA 激活(最新)

    注:此文以 Mac 为例,Windows 的激活方法也大同小异.如果不差钱的话,建议购买正版! 1.下载安装 直接通过下面的链接到官网下载最新的 Ultimate 版本即可: https://www. ...

  6. mysql 输入show databases 没反应

    我是小白,大佬勿喷 *** mysql 输入show databases 没反应 一句话 不要忘记使用MySQL时在命令后加;哦 * * * 在Linux输入以下命令 mysql 终端显示以下文本 W ...

  7. 2019-SUCTF-web记录

    1.web1-chkin 首先发现服务器中间件为nginx,并且fuzz上传过滤情况,是黑名单,带ph的全部不能上传切对文件内容中包含<?进行过滤,并且服务器对文件头有exif_type的判断, ...

  8. 使用MTA HTML5统计API来分析数据

    使用MTA HTML5统计API来分析数据 在开发个人博客的时候,用到了腾讯移动分析(MTA),相比其他数据统计平台来说我喜欢她的简洁高效,易上手,同时文档也比较全面,提供了数据接口供用户调用. 在看 ...

  9. LoRaWAN_stack移植笔记(四)__RTC

    stm32相关的配置 由于例程使用的主控芯片为STM32L151C8T6,而在本设计中使用的主控芯片为STM32L051C8T6,内核不一样,并且Cube库相关的函数接口及配置也会有不同,所以芯片的驱 ...

  10. 使用Makefile构建Docker

    使用Makefile构建Docker 刚开始学习docker命令的时候,很喜欢一个字一个字敲,因为这样会记住命令.后来熟悉了之后,每次想要做一些操作的时候就不得不 重复的输入以前的命令.当切换一个项目 ...