CF991D Bishwock 第十七 贪心
1 second
256 megabytes
standard input
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.
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 + ;
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 第十七 贪心的更多相关文章
- CF991D Bishwock
CF991D Bishwock 题目描述 给一个$2\times n$的网格,上面一些位置以及被覆盖上了.现在你有一种形状为L的小块,每个由三个小格组成,构成L型 现在问你,当前的网格最多还能摆多少小 ...
- G、CSL 的训练计划【BFS 贪心】(“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛)
题目传送门:https://ac.nowcoder.com/acm/contest/551/G 链接:https://ac.nowcoder.com/acm/contest/551/G来源:牛客网 题 ...
- D、CSL 的字符串 【栈+贪心】 (“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛)
题目传送门:https://ac.nowcoder.com/acm/contest/551#question 题目描述 CSL 以前不会字符串算法,经过一年的训练,他还是不会……于是他打算向你求助. ...
- “新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛(D题,贪心+栈)
链接:https://ac.nowcoder.com/acm/contest/551/D来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言10485 ...
- 经典算法题每日演练——第十七题 Dijkstra算法
原文:经典算法题每日演练--第十七题 Dijkstra算法 或许在生活中,经常会碰到针对某一个问题,在众多的限制条件下,如何去寻找一个最优解?可能大家想到了很多诸如“线性规划”,“动态规划” 这些经典 ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- 我的MYSQL学习心得(十七) 复制
我的MYSQL学习心得(十七) 复制 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- codeforces 322 A Ciel and Dancing
题目链接 题意: 有n个男孩和m个女孩,他们要结对跳舞,每对要有一个女孩和一个男孩,而且其中一个要求之前没有和其他人结对,求出最大可以结多少对. 如图,一条线代表一对,只有这样三种情况. #inclu ...
- RocketMQ中Producer消息的发送
上篇博客介绍过Producer的启动,这里涉及到相关内容就不再累赘了 [RocketMQ中Producer的启动源码分析] Producer发送消息,首先需要生成Message实例: public c ...
- Something wrong with EnCase v8 index search results
My friend told me that she installed EnCase v8.05 on her workstation which OS version is Win 10. She ...
- 保存MTLAB图片是想去掉白边
在做一些matlab小实验的时候,生成的图片需要临时保存的时候会有多余的白边,如何能解决这种问题? 输入 iptsetpref('ImshowBorder','tight'); 后,再show一次图即 ...
- IDED中配置SVN没有svn.exe解决办法
首先在idea中配置svn时
- Unity经典游戏编程之:球球大作战
版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...
- 0x03 前缀和与差分
前缀和 [例题]BZOJ1218 激光炸弹 计算二位前缀和,再利用容斥原理计算出答案即可. #include <iostream> #include <cstdio> #inc ...
- LeetCode 85. 冗余连接 II
题目: 在本问题中,有根树指满足以下条件的有向图.该树只有一个根节点,所有其他节点都是该根节点的后继.每一个节点只有一个父节点,除了根节点没有父节点. 输入一个有向图,该图由一个有着N个节点 (节点值 ...
- Scala集合(四)
1. 集合 集合主要有三种: Sequence Map Set sequence是一种线性元素的集合,可能会是索引或者线性的(链表).map是包含键值对的集合,就像Java的Map,set是包含无重复 ...
- Oracle中查看最近被修改过的表的方法
1.select uat.table_name from user_all_tables uat 该SQL可以获得所有用户表的名称 2.select object_name, created,last ...