zoukankan      html  css  js  c++  java
  • Codeforces Round #442 (Div. 2)

    A. Alex and broken contest
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.

    But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.

    It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".

    Names are case sensitive.

    Input

    The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100— the name of the problem.

    Output

    Print "YES", if problem is from this contest, and "NO" otherwise.

    Examples
    input
    Alex_and_broken_contest
    output
    NO
    input
    NikitaAndString
    output
    YES
    input
    Danil_and_Olya
    output
    NO

     那几个人名只出现一个人名出现一次,这个是题意杀,是真烦

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        string s;
        cin>>s;
        int ans=0;
        for(int i=0; s[i]; i++)
        {
            if(s.find("Danil",i)==i)ans++;
            if(s.find("Olya",i)==i)ans++;
            if(s.find("Slava",i)==i)ans++;
            if(s.find("Ann",i)==i)ans++;
            if(s.find("Nikita",i)==i)ans++;
        }
        printf("%s",(ans==1)?"YES":"NO");
        return 0;
    }
    B. Nikita and string
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    One day Nikita found the string containing letters "a" and "b" only.

    Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".

    Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

    Input

    The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".

    Output

    Print a single integer — the maximum possible size of beautiful string Nikita can get.

    Examples
    input
    abba
    output
    4
    input
    bab
    output
    2
    Note

    It the first sample the string is already beautiful.

    In the second sample he needs to delete one of "b" to make it beautiful.

     dp一下吧,统计ab个数,改改数据又是一道新题,因为n^2的做法不优秀

    #include <bits/stdc++.h>
    using namespace std;
    char a[5010];
    int B[5010],A[5010];
    int main()
    {
        scanf("%s",a+1);
        int l=strlen(a+1);
        for(int i=1; i<=l; i++)
        {
            A[i]=A[i-1];
            B[i]=B[i-1];
            if(a[i]=='a')
                A[i]++;
            else
                B[i]++;
        }
        int ans=0;
        for(int i=0; i<=l; i++)
            for(int j=i; j<=l; j++)
                ans=max(ans,A[l]+A[i]-A[j]+B[j]-B[i]);
        printf("%d",ans);
        return 0;
    }

    c代表只有一串a的长度,b代表只有一串啊和b的最长长度,a代表一串a一串b再一串a的最大长度

    #include <bits/stdc++.h>
    using namespace std;
    char s[5010];
    int main()
    {
        scanf("%s",s+1);
        int a=0,b=0,c=0;
        for(int i=1; s[i]; i++)
        {
            if(s[i]=='a')
            a++,c++;
            else
            b++;
            a=max(a,b);
            b=max(c,b);
        }
        printf("%d",a);
        return 0;
    }

    这个c拿来构造一波吧

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0),cout.tie(0);
        int n;
        cin>>n;
        cout<<(n/2)*2+(n+1)/2<<'
    ';
        for(int i=2;i<=n;i+=2)
            cout<<i<<" ";
        for(int i=1;i<=n;i+=2)
            cout<<i<<" ";
        for(int i=2;i<=n;i+=2)
            cout<<i<<" ";
        return 0;
    }
  • 相关阅读:
    javascript实现俄罗斯方块游戏
    HTML5 SSE 数据推送应用开发
    一次实习生面试经历
    前端工作面试问题(上)
    关于写好这个“简历”的几点思考
    ROS机器人的系统构建-连接摄像头、连接kinect、连接激光雷达
    opencv 轮廓的外围多边形提取或者 删除最小最大轮廓
    opencv 轮廓点的坐标大小的修改
    opencv 轮廓的外围多边形提取或者删除最小最大轮廓
    opencv 容器的使用vector<std::vector<cv::Point>> or 轮廓存储到容器中
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7726322.html
Copyright © 2011-2022 走看看