#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
char s[100007];
int main(){
cin>>s+1;
int n=strlen(s+1);
int cnt=0;
for(int i=n;i>=1;--i){//从后向前,保证后面的解都是合法的情况下
if(s[i]=='1'){//如果当前位置的数字是1
if(cnt)//i后面1的个数小于0的个数,此时如果把i位置从1变成0会导致以i为起点的最长非递减串增长(0的个数加一了),所以不可以变,把后面0比1多的个数减一即可
cnt--;
else//i后面1的个数大于等于0的个数,此时以i为起点的最长非递减串长度为1的个数,所以把i的1改成0并不会影响长度
s[i]='0';
}
else if(s[i]=='0')//如果当前位置的数字是0
cnt++;//s[i]一定是后面以i为起点的区间的最长非递减串的一部分,所以t[i]必须为0,否则t中以i为起点len为终点的最长非递减串长度将会小于s中的长度
}
for(int i=1;i<=n;++i)
cout<<s[i];
return 0;
}

Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)的更多相关文章

  1. Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学

    Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学 [Problem Description] ...

  2. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  3. 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)

    题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...

  4. 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 ...

  5. Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)

    A. BowWow and the Timetable time limit per test1 second memory limit per test256 megabytes inputstan ...

  6. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  7. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  8. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  9. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

随机推荐

  1. jinja 语法 - 整型转字符串

    大多数 jinja 相关的问题,其实查文档就解决了,但后来遇到这个问题,使得我把 jinja 官方文档,api.样例等,认真读了个遍= =. 发现没有直接的办法可以将整型转为字符串,对于需要进行字符串 ...

  2. 解决linux乱码问题

    echo "LANG="zh_CN.UTF-8" >> /etc/sysconfig/i18n yum -y install kde-l10n-Chinese ...

  3. 安卓开发:图片的显示Mode

    安卓开发中将图片放置在ImageView中展示,涉及到图片显示的模式,跟iOS开发中UIView的contentMode属性是一个意思,在安卓UI元素中使用的属性是scaleType,其中枚举值的效果 ...

  4. Dataguard单机—>单机

    本演示案例所用环境: primary Standby OS Hostname CHINA-DB1 CHINA-DB2 OS Version SUSE Linux Enterprise Server 1 ...

  5. kettel路径配置

    背景 kettel 8.3 jdk13.0.1 jre1.8.0 配置 PENTAHO_JAVA_HOME:C:\Program Files (x86)\Java\jre1.8.0_241 JAVA_ ...

  6. netty笔记-:EpollEventLoopGroup:Caused by: java.lang.ExceptionInInitializerError:Caused by: java.lang.IllegalStateException: Only supported on Linux

    今天在翻看netty的源码的时候发现netty对EventLoopGroup的实现有不止常用的NIOEventLoopGroup ,一共有以下几种. EpollEventLoopGroup NioEv ...

  7. 【PAT甲级】1085 Perfect Sequence (25 分)

    题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...

  8. 【C语言】将输入的10个整数逆序输出

    代码1: #include <stdio.h> int main() { ], b[]; int i,j; printf("请输入10个整数:\n"); ; i < ...

  9. 04-Docker-Container管理操作

    目录 04-Docker-Container管理操作 参考 容器运行须知 容器生命周期 容器管理命令 1. 生命周期 2. 查看操作 3. 命令执行 4. 文件复制 容器用途分类 04-Docker- ...

  10. CSS - px、em、%

    px(像素).em.% 百分比 1. em 1.1 本元素给定字体的 font-size 值,如果元素的 font-size 为 14px ,那么 1em = 14px:如果 font-size 为 ...