zoukankan      html  css  js  c++  java
  • hdu 6034 Balala Power!

    Balala Power!

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 3555    Accepted Submission(s): 844


    Problem Description

    Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two different characters should not be changed into the same number) so that he could calculate the sum of these strings as integers in base 26 hilariously.

    Mr.Tang wants you to maximize the summation. Notice that no string in this problem could have leading zeros except for string "0". It is guaranteed that at least one character does not appear at the beginning of any string.

    The summation may be quite large, so you should output it in modulo 109+7.
     
    Input
    The input contains multiple test cases.

    For each test case, the first line contains one positive integers n, the number of strings. (1n100000)

    Each of the next n lines contains a string si consisting of only lower case letters. (1|si|100000,|si|106)
     
    Output
    For each test case, output "Case #xy" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
     
    Sample Input
    1
    a
    2
    aa
    bb
    3
    a
    ba
    abc
     
    Sample Output
    Case #1: 25
    Case #2: 1323
    Case #3: 18221
     
    Source
    Recommend
    liuyiding   |   We have carefully selected several similar problems for you:  6044 6043 6042 6041 6040 
     
    #include <iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<bits/stdc++.h>
    
    using namespace std;
    const long long mod=1e9+7;
    struct node
    {
        int id;
        double k;
    }a[30];
    int b[30];
    long long num[30][100005];
    bool vis[30];
    char ch[100005];
    int n,maxlen;
    
    bool cmp(node a,node b)
    {
        return a.k>b.k;
    }
    int main()
    {
        int cas=0;
        while(~scanf("%d",&n))
        {
             maxlen=0;
             memset(num,0,sizeof(num));
             memset(vis,0,sizeof(vis));
            for(;n>0;n--)
            {
                scanf("%s",&ch);
                int l=strlen(ch);
                maxlen=max(maxlen,l);
                if (l>1) vis[ch[0]-'a']=1;
                for(int i=0;i<l;i++)
                    num[ch[i]-'a'][l-i-1]++;
            }
    
            for(int i=0;i<26;i++)
            {
                a[i].id=i; a[i].k=0;
                for(int j=0;j<maxlen;j++)
                    a[i].k=a[i].k/26+num[i][j];
            }
    
            sort(a,a+26,cmp);
    
            for(int i=25;i>=0;i--)
            {
                if (vis[a[i].id]) continue;
                  else
                  {
                      int cnt=25;
                      for(int j=0;j<26;j++)
                        if (j!=i) b[a[j].id]=cnt--;
                            else b[a[j].id]=0;
                      break;
                  }
            }
    
            long long ans=0;
            for(int i=0;i<26;i++)
            {
                long long ret=1;
               for(int j=0;j<maxlen;j++)
               {
                   ans=(ans+num[i][j]*ret*b[i])%mod;
                   ret=(ret*26)%mod;
               }
            }
            printf("Case #%d: %lld
    ",++cas,ans);
        }
        return 0;
    }
  • 相关阅读:
    set集合 深浅拷贝
    2015 ACM/ICPC Asia Regional Changchun Online Pro 1005 Travel (Krsukal变形)
    2015 ACM/ICPC Asia Regional Changchun Online Pro 1002 Ponds(拓扑排序+并查集)
    Codeforces Round #319 (Div. 2) B Modulo Sum (dp,鸽巢)
    Codeforces Round #319 (Div. 2) C Vasya and Petya's Game (数论)
    UVA 11468 Substring (AC自动机)
    UVA11019 Matrix Matcher (AC自动机)
    UVALive 4670 Dominating Patterns (AC自动机)
    UVALive 3026 Period (KMP算法简介)
    UVA 11732 strcmp() Anyone (Trie+链表)
  • 原文地址:https://www.cnblogs.com/stepping/p/7240175.html
Copyright © 2011-2022 走看看