• Codeforces Round #253 (Div. 2)


    A. Anton and Letters
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.

    Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.

    Input

    The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.

    Output

    Print a single number — the number of distinct letters in Anton's set.

    Sample test(s)
    input
    {a, b, c}
    
    output
    3
    
    input
    {b, a, b, a}
    
    output
    2
    
    input
    {}
    
    output
    0
    


    //15 ms	 0 KB
    #include<stdio.h>
    #include<string.h>
    char s[1007];
    int z[30];
    int main()
    {
        gets(s);
        int len=strlen(s),count=0;
        memset(z,0,sizeof(z));
        for(int i=0;i<len;i++)
        {
            if(s[i]>='a'&&s[i]<='z')
                z[s[i]-'a'+1]++;
        }
        for(int i=1;i<=26;i++)
            if(z[i])count++;
        printf("%d
    ",count);
    }

    B. Kolya and Tandem Repeat
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

    Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?

    See notes for definition of a tandem repeat.

    Input

    The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.

    Output

    Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.

    Sample test(s)
    input
    aaba
    2
    
    output
    6
    
    input
    aaabbbb
    2
    
    output
    6
    
    input
    abracadabra
    10
    
    output
    20
    
    Note

    A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.

    In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.

    //15 ms	 0 KB
    #include<stdio.h>
    #include<string.h>
    char s[1007];
    int main()
    {
        int n;
        scanf("%s",s);
        scanf("%d",&n);
        int len=strlen(s),maxlen=0;
        if(n>=len){printf("%d
    ",(n+len)/2*2);return 0;}//假设加入的长度大于等于原串长度
        for(int i=1;i<len;i++)//求在加入之前原串符合条件的最长长度
            for(int j=0;j<len;j++)
            {
                int flag=0;
                for(int k=j,num=1;num<=i;num++,k++)
                    if(s[k]!=s[k+i]){flag=1;break;}
                if(!flag){maxlen=i;break;}
            }
        int maxx=n+len;
        int a=maxx/2;
        for(int i=a;i>=0;i--)//枚举加入之后的最长长度
        {
            int flag=0;
            for(int j=len-1,num=1;num<=(i-n);j--,num++)
                if(s[j]!=s[len-i-num]){flag=1;break;}
            if(!flag)
            {
                if(i>maxlen)printf("%d
    ",i*2);
                else printf("%d
    ",maxlen*2);
                break;
            }
        }
    }
    

    D. Andrey and Problem
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.

    Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.

    Input

    The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi(0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.

    Output

    Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.

    Sample test(s)
    input
    4
    0.1 0.2 0.3 0.8
    
    output
    0.800000000000
    
    input
    2
    0.1 0.2
    
    output
    0.260000000000
    
    Note

    In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.

    In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.

    题意是说给你n个数,每一个数代表为1的概率是多少,让你从中选择一个或者多个数使其概率为1的最大。

    将n个数从大到小排序,假设选择一个要使概率最大,则肯定选择第一个数。

    假设选择两个使其概率最大,则肯定选择前两个数,选择三个。则选择前三个数,以此推类。

    仅仅要求出前一个到前n个全部情况。然后取最大即是所求。

    //31 ms	 0 KB
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    double s[107];
    int cmp(double a,double b){return a>b;}
    int main()
    {
        int n;
        double maxx=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)scanf("%lf",&s[i]);
        sort(s,s+n,cmp);
        for(int i=1;i<=n;i++)
        {
            double ans=0;
            for(int j=0;j<i;j++)
            {
                double a=s[j];
                for(int k=0;k<i;k++)
                    if(k!=j)a*=1-s[k];
                ans+=a;
            }
            maxx=max(maxx,ans);
        }
        printf("%.12lf
    ",maxx);
    }
    


  • 相关阅读:
    [College] C++字符串读入与进制转化-关于《实践教程》P10[程序]的一些总结
    [College] 二进制与机器数的几种形式
    [College] Hello World!
    [SinGuLaRiTy] 复习模板-数学
    ByteCTF 2020 KOP Writeup
    【题解】电子科技大学第十八届 ACM 程序设计竞赛
    【逆向】某 VR 驱动分析过程
    物联网框架 IoTivity 中间人攻击分析
    批处理工具 CAPI 逆向分析之 API Call
    DASCTF 2020 六月赛 Reverse Writeup
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/7190267.html
Copyright © 2020-2023  润新知