zoukankan      html  css  js  c++  java
  • Codeforces 1204D2 Kirk and a Binary String (hard version)

    D1. Kirk and a Binary String (easy version)
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.

    Kirk has a binary string ss (a string which consists of zeroes and ones) of length nn and he is asking you to find a binary string tt of the same length which satisfies the following conditions:

    • For any ll and rr (1lrn1≤l≤r≤n) the length of the longest non-decreasing subsequence of the substring slsl+1srslsl+1…sr is equal to the length of the longest non-decreasing subsequence of the substring tltl+1trtltl+1…tr;
    • The number of zeroes in tt is the maximum possible.

    A non-decreasing subsequence of a string pp is a sequence of indices i1,i2,,iki1,i2,…,ik such that i1<i2<<iki1<i2<…<ik and pi1pi2pikpi1≤pi2≤…≤pik. The length of the subsequence is kk.

    If there are multiple substrings which satisfy the conditions, output any.

    Input

    The first line contains a binary string of length not more than 20002000.

    Output

    Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.

    题意
    给出一个 串 S ,求一个串 T , 要求LIS等长,所有区间的 LIS  相等,0 的个数尽可能多

    解:

    从后往前贪心, 保证后面的解都是合法的

     假如当前是0 作为起点 对后面的Lis 无影响

    假如当前是 1   假如不是以他为起点 对于LIS 起点为0 的 那么 变为0 就一定更改lis  但是1的个数>= 0 的个数时可以改

    假如当前是 1   假如是以他为起点 那么 就变为0 就一定不会更改lis  

    所以 但是当 $ tot1>=tot0  $ 时 可以没有影响 可以改

    //
    #include<bits/stdc++.h>
    using namespace std;
    string s;
    int main()
    {
        cin>>s;
        int tot1=0,tot2=0;
        for(int i=s.size()-1;i>=0;i--)
        {
            if(s[i]=='1') if(tot1>=tot2) s[i]='0';else tot1++;
            else
            {
                tot2++;
            }
            
        }
        cout<<s;
        
    }
    刀剑映出了战士的心。而我的心,漆黑且残破
  • 相关阅读:
    Linux监控和安全运维 2.0 zabbix配置邮件告警
    Linux监控和安全运维 1.9 zabbix增加客户端监控
    linux系统构架
    给虚拟机添加eth1网络适配器(网卡)
    linux系统构架
    linux系统构架
    Linux系统构架
    VIM-Sed常用的一些记录。。。逐渐学习。。
    AIX用chsec命令修改快捷修改配置文件
    SYSLOG审记日志的配置。
  • 原文地址:https://www.cnblogs.com/OIEREDSION/p/11399633.html
Copyright © 2011-2022 走看看