• 【水】CF#FF(255)Div2 A,B


    解释

    听说codeforces的题目都很难,于是我小心翼翼,胆颤心惊地做了一下,特意从div2开始做。。

    怎么说呢,哎。。这种水题本来不应该放的。。但是毕竟是cf的题目,还是将就吧

    Div 2 A

                                                                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
    

    翻译&&思路

    给你一堆的值和一个弱爆了的hash方式(mod P),要求第一次冲突时间(插入第k个元素之后)

    数据范围小的可怜,按着他的要求做就可以了。。。

    代码

      

    #include<iostream>
    #include<cstdlib>
    #include<cstdio>
    using namespace std;
    int a[305]={0};
    int main()
    {
         int n,t,p;
         cin>>p>>n;
         for (int i=1;i<=n;i++)
         {
          cin>>t;
          if ((a[t%p])==1) {cout<<i;return 0;}
                           else {a[t%p]=1;}
        }
        cout<<-1;
        return 0;
    }

    Div 2 B

    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
    

    翻译&&思路

    给出一个字符串和增加操作次数k,并给出26个小写字母各自的权值,求最大权值。

    字符串权值函数(即位权与值权乘积的总和)

    我乍一看觉得没这么简单,想一想好像还真是这么简单。。。。

    就是算出原先字符串的权值,然后把值权最大的字母放K个到最后..(位权最大)...完了。。

    代码

    #include<iostream>
    #include<cstdlib>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int best;
    int a[1005];
    long long sum;
    char str[10005];
    int main()
    {
        int i,j,k;
        cin>>str;
        cin>>k;
        best=-1;
        for (int i=1;i<=26;i++)
            {
            cin>>a[i];
            best=max(best,a[i]); 
            }
        sum=0;
        int m=strlen(str);
        for (int i=0;i<m;i++) 
        {
                sum+=(a[int(str[i])-int('a')+1]*(i+1));
            }
        int p=m-1;
        while (k>0) {p++;sum+=best*(p+1); k--;}
        cout<<sum<<endl;
        return 0;
    }

    吐槽

     cf为何不能有格式地复制啊哇哇哇,简直了。。这么卡这么难用,一点都不友好。

    noip忘记取模的痛
  • 相关阅读:
    微信公众号平台接口开发:基础支持,获取微信服务器IP地址
    微信公众号平台接口开发:基础支持,获取access_token
    微信公众号平台接口开发:发送客服消息
    asp.net权限认证篇外:集成域账号登录
    asp.net权限认证:OWIN实现OAuth 2.0 之简化模式(Implicit)
    asp.net权限认证:OWIN实现OAuth 2.0 之授权码模式(Authorization Code)
    asp.net权限认证:OWIN实现OAuth 2.0 之密码模式(Resource Owner Password Credential)
    asp.net权限认证:OWIN实现OAuth 2.0 之客户端模式(Client Credential)
    window配置ftp服务,代码客户端上传下载文件
    制作OpenStack使用的windows镜像
  • 原文地址:https://www.cnblogs.com/seekdreamer/p/3843718.html
Copyright © 2020-2023  润新知