CF1204D Kirk and a Binary String
problem
给出一个长度为\(n(n\le 10^5)\)的只包含01的字符串。把尽可能多的1变为0,使得对于所有的\(l \in [1,n],r\in [l,n]\),区间\([l,r]\)的最长不下降子序列的长度不变。
solution
【译自官方题解】
可以发现有些字符是确定的(即无法修改)。这些确定的字符满足以下几个条件。
- 所有的\(10\)是确定的。
- 如果字符串\(p\)是确定的且字符串\(q\)是确定的,那么字符串\(pq\)是确定的。
- 如果字符串\(p\)是确定的,那么字符串\(1p0\)是确定的。
- 根据以上三个性质可以推出,所有确定的字符串中0和1的个数相同
- 确定的字符串的最长不降子序列长度为该字符串长度的一半。具体的就是取全部的1或全部的0。
【下方内容为自己YY】
然后考虑如何具体实现。发现上面的5条性质(其实是前3条)与括号序列相同。所以实现就非常简单了。将1看做左括号,0看做右括号。最后将不能匹配的左括号全部变为0即可。
code
/*
* @Author: wxyww
* @Date: 2019-08-21 15:00:10
* @Last Modified time: 2019-08-21 15:01:55
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
#include<cmath>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int N = 100000 + 100;
ll read() {
ll x = 0,f = 1; char c = getchar();
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0',c = getchar();}
return x * f;
}
char s[N];
int a[N],top;
int main() {
scanf("%s",s + 1);
int n = strlen(s + 1);
for(int i = 1;i <= n;++i) {
if(s[i] == '1') a[++top] = i;
else if(top) --top;
}
while(top) s[a[top--]] = '0';
printf("%s",s + 1);
return 0;
}
CF1204D Kirk and a Binary String的更多相关文章
- D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)
D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...
- D1. Kirk and a Binary String (easy version)
D1. Kirk and a Binary String (easy version) 01串找最长不降子序列 给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致 从后 ...
- Codeforces 1204D Kirk and a Binary String - 数学
题目传送门 传送门 群除我均会猜结论/找规律,sad.... 以下内容只保证代码能过system test,证明应该都是在纯口胡 约定下文中的$LIS$表示最长不下降子序列. 定义$zero(s)$表 ...
- 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)
题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...
- Codeforces 1204D2. Kirk and a Binary String (hard version) (dp思路)
题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl ...
- Binary String Matching
问题 B: Binary String Matching 时间限制: 3 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...
- NYOJ之Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose a ...
- ACM Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- Binary String Matching(kmp+str)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
随机推荐
- [译]发布ABP v0.19包含Angular UI选项
发布ABP v0.19包含Angular UI选项 ABP v0.19已发布,包含解决的~90个问题和600+次提交. 新功能 Angular UI 终于,ABP有了一个SPA UI选项,使用最新的A ...
- Luogu P5408 【模板】第一类斯特林数·行
为什么要做这题呢,当然是有用啊qwq 首先我们考虑非常经典的式子: \[x^{\overline{n}}=\sum_i \left[^n_i\right] x^i\] 然后上倍增: \[x^{\ove ...
- Unity TextMeshPro 一键生成工具
本文参考了这片博客文章,在此基础上进行优化和改进: https://blog.csdn.net/akof1314/article/details/80868869 先截张效果图: TextMeshPr ...
- elasticsearch 索引的使用(配合haystack)
1,# 从仓库拉取镜像$ sudo docker image pull delron/elasticsearch-ik:2.4.6-1.02,下载elasticsearc-2.4.6目录拷贝到home ...
- 【广州.NET社区推荐】.NET Core Q&A - ORM
Object/Relational Mapping(ORM) 作为开发工作中非常重要的组件,重量级.轻量级.简单的.复杂的 各种各样有很多种适应不同的业务场景,但这些组件分散在网络世界的各个角落,寻找 ...
- Java8新特性——集合底层源码实现的改变
ArrayList 源码分析: jdk7: ArrayList list = new ArrayList();//初始化一个长度为10的Object[] elementData sysout(list ...
- [IDA]系统注释给改掉
IDA系统自动注释的,如果按 ';',则不会修改成功. 应该按 Shift + ; 这样才可以修改.
- python 对Unicode解码
打印: print('我喜欢你'.encode('unicode_escape')) 得到Unicode编码: b'\\u6211\\u559c\\u6b22\\u4f60 将上面的编码赋值给str后 ...
- Flask 教程 第二章:模板
本文翻译自 The Flask Mega-Tutorial Part II: Templates 在Flask Mega-Tutorial系列的第二部分中,我将讨论如何使用模板. 学习完第一章之后,你 ...
- CAD如何能画的快?老师傅教你5个技巧,远超他人
都知道CAD用途是很广泛,各行各业都是离不开CAD画图设计,机械,建筑,园林,服装,家具…… 画图速度一定要够快速,这样才能够满足需求,事实上会发现有的人绘图非常快速,但是你出一张图却要加班赶点.差距 ...