• Codeforces Round #FF (Div. 2)


    A. DZY Loves Hash
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b.

    However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1.

    Input

    The first line contains two integers, p and n (2 ≤ p, n ≤ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≤ xi ≤ 109).

    Output

    Output a single integer — the answer to the problem.

    Sample test(s)
    input
    10 5
    0
    21
    53
    41
    53
    
    output
    4
    
    input
    5 5
    0
    1
    2
    3
    4
    
    output
    -1

    //31 ms	 0 KB
    #include<stdio.h>
    #include<string.h>
    int s[307],vis[307];
    int main()
    {
        int p,n;
        while(scanf("%d%d",&p,&n)!=EOF)
        {
            memset(vis,0,sizeof(vis));
            int flag=-1;
            for(int i=0;i<n;i++)
                scanf("%d",&s[i]);
            for(int i=0;i<n;i++)
            {
                int a=s[i]%p;
                if(!vis[a])vis[a]=1;
                else {flag=i+1;break;}
            }
            printf("%d
    ",flag);
        }
        return 0;
    }
    

    B. DZY Loves Strings
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where

    Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?

    Input

    The first line contains a single string s (1 ≤ |s| ≤ 103).

    The second line contains a single integer k (0 ≤ k ≤ 103).

    The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.

    Output

    Print a single integer — the largest possible value of the resulting string DZY could get.

    Sample test(s)
    input
    abc
    3
    1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    
    output
    41
    
    Note

    In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.


    //30 ms	 0 KB
    #include<stdio.h>
    #include<string.h>
    char s[1007];
    int v[26];
    int main()
    {
        scanf("%s",s);
        int n,ans=0,maxx=-1;
        scanf("%d",&n);
        for(int i=0;i<26;i++)
        {
            scanf("%d",&v[i]);
            if(v[i]>maxx)maxx=v[i];
        }
        int len=strlen(s);
        for(int i=0;i<len;i++)
            ans+=((i+1)*v[s[i]-'a']);
        for(int i=len+1;i<=len+n;i++)
            ans+=(i*maxx);
        printf("%d
    ",ans);
    }

    C. DZY Loves Sequences
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    DZY has a sequence a, consisting of n integers.

    We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.

    Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.

    You only need to output the length of the subsegment you find.

    Input

    The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

    Output

    In a single line print the answer to the problem — the maximum length of the required subsegment.

    Sample test(s)
    input
    6
    7 2 3 1 5 6
    
    output
    5
    
    Note

    You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.


    给你一个序列S。让你能够改变序列中的一个值。使得此序列的一个子序列为上升序列。

    求此子序列最长是多少。

    设r[i]为在位置i上最长的上升序列个数(从序列头開始),l[i]为在位置i上最长的上升序列的个数(从序列尾開始)。

    假设S[i+1]-S[i-1]>1,那么最长可能是max(ans,r[i-1]+l[i+1]+1)

    否则最长可能是max(ans,max(r[i-1],l[i+1])+1)

    //46 ms	 1200 KB
    #include<stdio.h>
    #include<algorithm>
    #define M 100007
    using namespace std;
    int s[M],r[M],l[M];
    int main()
    {
        int n,ans;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&s[i]);
        r[1]=1;
        for(int i=2;i<=n;i++)
            if(s[i]>s[i-1])r[i]=r[i-1]+1;
            else r[i]=1;
        l[n]=1;
        for(int i=n-1;i>=1;i--)
            if(s[i]<s[i+1])l[i]=l[i+1]+1;
            else l[i]=1;
        ans=max(r[n],l[1])+1;
        for(int i=2;i<=n-1;i++)
            if(s[i-1]<s[i+1]-1)ans=max(ans,r[i-1]+l[i+1]+1);
            else ans=max(ans,max(r[i-1],l[i+1])+1);
        if(ans>n)ans=n;
        printf("%d
    ",ans);
    }
    


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    【学习小记】一般图最大匹配——带花树算法
    如何检查oracle的归档空间是否满了
    Linux 的计划任务
    转 oracle的热备份和冷备份
    SQLException: Io 异常: Connection refused ERR=12514 ERR=1153异常处理过程
    查看oracle数据库版本
    ORACLE默认实例设置--linux
    oracle查看用户属于哪个表空间
    oracle默认数据库实例
    oracle 查看用户所在的表空间
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4732256.html
Copyright © 2020-2023  润新知