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

     题意  是否所有名字中只出现一次

    AC代码

     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 #include <iostream>
     6 #include <sstream>
     7 #include <algorithm>
     8 #include <string>
     9 #include <queue>
    10 #include <vector>
    11 using namespace std;
    12 const int maxn= 1e5+10;
    13 const int maxm= 1e4+10;
    14 const int inf = 1008611;
    15 typedef long long ll;
    16 string  a;
    17 string b[5]={"Danil","Olya","Slava","Ann","Nikita"};
    18 int main()
    19 {
    20     cin>>a;
    21     int sum=0;
    22     for(int i=0;i<5;i++)
    23     {
    24         if(a.find(b[i])!=-1)    //find找到子串第一次出现的位置返回下标
    25             sum++;
    26         if(a.rfind(b[i])!=a.find(b[i]))   //rfind找到子串最后一次出现的位置返回下标
    27             sum++;
    28     }
    29     if(sum>1||sum==0)
    30         printf("NO
    ");
    31     else
    32         printf("YES
    ");
    33     return 0;
    34 }
    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.

     解析  前缀和暴力枚举所有划分

     AC代码

     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 #include <iostream>
     6 #include <sstream>
     7 #include <algorithm>
     8 #include <string>
     9 #include <queue>
    10 #include <vector>
    11 using namespace std;
    12 const int maxn= 1e5+10;
    13 const int maxm= 1e4+10;
    14 const int inf = 0x3f3f3f3f;
    15 typedef long long ll;
    16 int a[maxn],b[maxn];
    17 char s[maxn];
    18 int main()
    19 {
    20     while(scanf("%s",s)!=EOF)
    21     {
    22         int len=strlen(s);
    23         a[0]=b[0]=0;
    24         for(int i=0;i<len;i++)  //一共 len 位 0~len-1
    25         {
    26             a[i+1]=a[i];         //a[i]表示第i位之前 不包括第i位 有多少个a
    27             b[i+1]=b[i];         //b[i]表示第i位之前 不包括第i位 有多少个b
    28             if(s[i]=='a')
    29                 a[i+1]++;
    30             else
    31                 b[i+1]++;
    32         }
    33         int maxx=0;
    34         for(int i=0;i<=len;i++)         //将 len-1位 划分为成 三个区间[1,i-1],[i,j-1],[j,len-1],枚举划分情况
    35         {
    36             for(int j=i;j<=len;j++)
    37             {
    38                 int now=a[i]+(b[j]-b[i])+(a[len]-a[j]);  //当前情况的长度 a + b + a
    39                 maxx=max(maxx,now);                      //更新最优值
    40             }
    41         }
    42         printf("%d
    ",maxx);
    43     }
    44 }

    C题  偶奇偶 来炸就好了 一共n+n/2次

    AC代码

     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 #include <iostream>
     6 #include <sstream>
     7 #include <algorithm>
     8 #include <string>
     9 #include <queue>
    10 #include <vector>
    11 using namespace std;
    12 const int maxn= 1e5+10;
    13 const int maxm= 1e4+10;
    14 const int inf = 1008611;
    15 typedef long long ll;
    16 int main()
    17 {
    18     int n;
    19     while(scanf("%d",&n)!=EOF)
    20     {
    21         int ans=n+n/2;
    22         printf("%d
    ",ans);
    23         for(int i=1;i<=n;i++)
    24         {
    25             if(i%2==0)
    26                 printf("%d ",i);
    27         }
    28         for(int i=1;i<=n;i++)
    29         {
    30             if(i%2==1)
    31                 printf("%d ",i);
    32         }
    33         for(int i=1;i<=n;i++)
    34         {
    35             if(i%2==0)
    36             {
    37                 if(i+2>n)
    38                     printf("%d
    ",i);
    39                 else
    40                     printf("%d ",i);
    41             }
    42         }
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    HDU2036 计算多边形的面积
    poj 3648 线段树成段更新
    线段树基本知识
    计算几何基本模板
    最长递增子序列问题—LIS
    poj 2503
    Python基础(5)_字符编码、文件处理
    Python基础(4)_字典、集合、bool值
    Python基础(3)_可变对象与不可变对象、列表、元祖和字典
    流程控制练习
  • 原文地址:https://www.cnblogs.com/stranger-/p/7732559.html
Copyright © 2011-2022 走看看