#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. redis-server.exe redis.windows.conf 报错

    在参考博文:https://blog.csdn.net/erlian1992/article/details/54382443#comments 学习redis的时候启动报错 C:\Users\Adm ...

  2. 深度学习之反向传播算法(BP)代码实现

    反向传播算法实战 本文仅仅是反向传播算法的实现,不涉及公式推导,如果对反向传播算法公式推导不熟悉,强烈建议查看另一篇文章神经网络之反向传播算法(BP)公式推导(超详细) 我们将实现一个 4 层的全连接 ...

  3. 大组合数Lucas

    https://blog.csdn.net/sr_19930829/article/details/39058487 LL Lucas(LL n, LL m, int p){ ; } Saving B ...

  4. springboot项目部署到服务器上

    链接:https://blog.csdn.net/qq_22638399/article/details/81506448#commentsedit 链接2:https://blog.csdn.net ...

  5. 吴裕雄 python 神经网络——TensorFlow 使用卷积神经网络训练和预测MNIST手写数据集

    import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...

  6. 【MySQL】库的操作

    "SQL语言主要用于存取数据.查询数据.更新数据和管理关系数据库系统,SQL语言由IBM开发. SQL语言分为3种类型: DDL语句 数据库定义语言:数据库.表.视图.索引.存储过程,例如C ...

  7. centos7.5下安装jenkins

    最近从头搭建了一套python+selenium+pytest+allure+Jenkins的环境,虽然网上挺多的,不过还是记录下来,毕竟坑还是挺多的....... 先从搭建jenkins开始把! 方 ...

  8. MySQL 将字符串转换为数字

    转载自:https://www.cnblogs.com/xiaoleiel/p/8316508.html 在操作mysql时,经常需要将字符转换成数字,这一步虽然简单,但不常用的话也很容易忘记,现将在 ...

  9. DVWA实验之Brute Force(暴力破解)- Medium

    DVWA实验之Brute Force(暴力破解)- Medium   有关DVWA环境搭建的教程请参考: https://www.cnblogs.com/0yst3r-2046/p/10928380. ...

  10. Educational Codeforces Round 82 C. Perfect Keyboard

    Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him ...