• Codeforces Round #418 (Div. 2)


    A. An abandoned sentiment from past
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.

    To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.

    Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.

    If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.

    Input

    The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and brespectively.

    The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.

    The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence.

    Input guarantees that apart from 0, no integer occurs in a and b more than once in total.

    Output

    Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.

    Examples
    input
    4 2
    11 0 0 14
    5 4
    output
    Yes
    input
    6 1
    2 3 0 8 9 10
    5
    output
    No
    input
    4 1
    8 94 0 4
    89
    output
    Yes
    input
    7 7
    0 0 0 0 0 0 0
    1 2 3 4 5 6 7
    output
    Yes
    Note

    In the first sample:

    • Sequence a is 11, 0, 0, 14.
    • Two of the elements are lost, and the candidates in b are 5 and 4.
    • There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".

    In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.

     上面有个序列中可能有0,然后你把下面的填回去看看是不是可能构成非递增序列,以下的代码比较好想,其实好像判断最大数能否插入就可以了。

    本来要在数据结构实验课做,但是那电脑做起来实在难受,完全看不清屏幕,跑回机房交了一发wa,考虑情况不够,机房也不安静,还是宿舍适合我,最近不打题了,手很生啊

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int n,k,f=0;
        scanf("%d%d",&n,&k);
        int a[105],b[105];
        for(int i=0;i<n;i++){
        scanf("%d",&a[i]);}
        for(int i=0;i<k;i++){
        scanf("%d",&b[i]);}
        sort(b,b+k);
        for(int i=0;i<n;i++){
            if(a[i]==0)
            a[i]=b[--k];
        }
        for(int i=1;i<n;i++){
            if(a[i]<a[i-1])
                f=1;
        }
        if(f)
            puts("Yes");
        else
            puts("No");
        return 0;
    }
    B. An express train to reveries
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.

    On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 to n inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with n meteorids, colours of which being integer sequences a1, a2, ..., an and b1, b2, ..., bn respectively. Meteoroids' colours were also between 1 and n inclusive, and the two sequences were not identical, that is, at least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.

    Well, she almost had it all — each of the sequences a and b matched exactly n - 1 elements in Sengoku's permutation. In other words, there is exactly one i (1 ≤ i ≤ n) such that ai ≠ pi, and exactly one j (1 ≤ j ≤ n) such that bj ≠ pj.

    For now, Sengoku is able to recover the actual colour sequences a and b through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.

    Input

    The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.

    The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst.

    The third line contains n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of colours in the second meteor outburst. At least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.

    Output

    Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.

    Input guarantees that such permutation exists.

    Examples
    input
    5
    1 2 3 4 3
    1 2 5 4 5
    output
    1 2 5 4 3
    input
    5
    4 4 2 3 1
    5 4 5 3 1
    output
    5 4 2 3 1
    input
    4
    1 1 3 4
    1 4 3 4
    output
    1 2 3 4
    Note

    In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.

    In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.

    这个题就是有两个序列,你要生成一个序列p,仅存在一个i,p[i]!=a[i];仅存在一个j,p[j]!=b[j];找到没有填的数和位置就好了

    这个B自己死活过不了,本来是没有把一个数和两个数的分开考虑,分开考虑了还是少考虑一种情况,然后就是自己打错数组名了。我这种手残的人还是不要复制粘贴了,真是简单的模拟啊

    #include <bits/stdc++.h>
    using namespace std;
    int a[10005],b[10005],c[10005],d[10005];
    int main() {
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
    scanf("%d",&b[i]);
    int s[2];
    int f=0;
    for(int i=0;i<n;i++){
    if(a[i]==b[i]){
    c[i]=a[i];
    d[a[i]]=1;}
    else
    s[f++]=i;}
    int sa[2];
    f=0;
    for(int i=1;i<=n;i++)
    if(!d[i])
    sa[f++]=i;
    if(f==1)
    c[s[0]]=sa[0];
    else{
    int f1=s[0],f2=s[1],f3=sa[0],f4=sa[1];
    if(a[f1]==f3&&b[f1]!=f3&&a[f2]!=f4&&b[f2]==f4||b[f1]==f3&&a[f1]!=f3&&a[f2]==f4&&b[f2]!=f4){
    c[f1]=f3;
    c[f2]=f4;
    }
    else{
    c[f1]=f4;
    c[f2]=f3;
    }
    }
    printf("%d",c[0]);
    for(int i=1;i<n;i++){
    printf(" %d",c[i]);
    }
    
    return 0;
    }
    C. An impassioned circulation of affection
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!

    Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from left to right, and the i-th piece has a colour si, denoted by a lowercase English letter. Nadeko will repaint at most m of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour c — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland.

    For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3.

    But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has q plans on this, each of which can be expressed as a pair of an integer mi and a lowercase letter ci, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan.

    Input

    The first line of input contains a positive integer n (1 ≤ n ≤ 1 500) — the length of the garland.

    The second line contains n lowercase English letters s1s2... sn as a string — the initial colours of paper pieces on the garland.

    The third line contains a positive integer q (1 ≤ q ≤ 200 000) — the number of plans Nadeko has.

    The next q lines describe one plan each: the i-th among them contains an integer mi (1 ≤ mi ≤ n) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter ci — Koyomi's possible favourite colour.

    Output

    Output q lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it.

    Examples
    input
    6
    koyomi
    3
    1 o
    4 o
    4 m
    output
    3
    6
    5
    input
    15
    yamatonadeshiko
    10
    1 a
    2 a
    3 a
    4 a
    5 a
    1 b
    2 b
    3 b
    4 b
    5 b
    output
    3
    4
    5
    7
    8
    1
    2
    3
    4
    5
    input
    10
    aaaaaaaaaa
    2
    10 b
    10 z
    output
    10
    10
    Note

    In the first sample, there are three plans:

    • In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable;
    • In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6;
    • In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5.

    有一个长度为n的字符串,有q次操作,每次可以改变x个为y,问最多的连续的y有几个

    qls的暴力做法,就是枚举啊

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN=1505;
    char s[MAXN];
    int main() {
        int n;
        scanf("%d%s",&n,s+1);
        int q;
        scanf("%d",&q);
        while(q--) {
            int m,res=0;
            char t[5];
            scanf("%d%s",&m,t);
            for(int l=1,r=1; l<=n; l++) {
                while(m>=(s[r]!=*t)&&r<=n)m-=(s[r++]!=*t);
                res=max(res,r-l);
                m+=(s[l]!=*t);
            }
            printf("%d
    ",res);
        }
        return 0;
    }

    还有题解给的奇淫做法,就是直接dp一下,求出所有的最大值

    #include <cstdio>
    #include <algorithm>
    using namespace std;
    static const int MAXN = 1502;
    static const int ALPHABET = 26;
    int n;
    char s[MAXN];
    int ans[ALPHABET][MAXN] = {{ 0 }};
    int q, m_i;
    char c_i;
    int main()
    {
        scanf("%d", &n); getchar();
        scanf("%s",s);
        for (char c = 0; c < ALPHABET; ++c) {
            for (int i = 0; i < n; ++i) {
                int replace_ct = 0;
                for (int j = i; j < n; ++j) {
                    if (s[j]-'a'!= c) ++replace_ct;
                    ans[c][replace_ct] = max(ans[c][replace_ct], j - i + 1);
                }
            }
            for (int i = 1; i < MAXN; ++i)
                ans[c][i] = max(ans[c][i], ans[c][i - 1]);
        }
    
        scanf("%d", &q);
        for (int i = 0; i < q; ++i) {
            scanf("%d %c", &m_i, &c_i);
            printf("%d
    ", ans[c_i - 'a'][m_i]);
        }
    
        return 0;
    }
  • 相关阅读:
    重写/覆盖基类的事件
    关于“日志”的输出控制
    WPF中DataGrid垂直滚动条滚动后导致每行CheckBox选择错乱
    WPF窗体应用程序开发
    C# 操作自定义config文件
    WPF绑定数据源之RelativeSource
    C# http请求 设置代理(标题可以作为搜索关键字)
    前端加载特效
    实现不同的项目,用不同的git 账号提交
    Casbin 使用记录
  • 原文地址:https://www.cnblogs.com/BobHuang/p/6960872.html
Copyright © 2020-2023  润新知