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;
        
    }
    刀剑映出了战士的心。而我的心,漆黑且残破
  • 相关阅读:
    测试某个方法的执行时间
    DataTable与DataGridView绑定
    《认知与设计——理解UI设计准则》笔记(7) 我们的注意力有限,记忆力也不完美
    常用软件收集
    通过反射得到某个实体的属性值
    获取某个字段的最大值
    C# ServerVariables参数说明
    C# 将网址转换为16进制可用网址,防盗链,%%
    不加修改权限的前提,要分辨出那些图片是删除不用的
    C# Winform 域名得到(查询)(服务器所在) IP  cs
  • 原文地址:https://www.cnblogs.com/OIEREDSION/p/11399633.html
Copyright © 2011-2022 走看看