17 多校 - 1 - 1002 - Balala Power! (HDU 6034)

21 篇文章 0 订阅

Balala Power!

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


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 # x y " 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
 


题意:给出n个字符串,每个字符串为一个26进制数,a-z 为 0-25 中任一个,不同字母所代表数字不同,求n个26进制数相加后,最大的值,用十进制表示。


先是对应找出相应字母所对应的值,将各个字母按权值排序,权值高的对应的数自然就大了。然后前导零是不能出现的,所以标记一下哪些字母不能为零的,0只有在所有字母均出现时才会出现,找能为零的字母中权值最小的一个令其为零,其他的就按权值从大到小排下来就行了

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
const int size = 101000;
int n,cas = 0,len,cnt,maxn,flag[30],use[30],vis[30];
ll mod = 1e9+7,add[size];
struct node
{
    int num[size];
    int letter;
}a[30];
bool cmp(node &a,node &b)
{
    for(int i=maxn;i>=0;i--)
    {
        if(a.num[i]==b.num[i])
            continue;
        else
            return a.num[i]>b.num[i];
    }
    return a.letter<b.letter;
}
char s[size];
int main()
{
    add[0]=1;
    for(int i=1;i<=size;i++)
        add[i] = (add[i-1] * 26) % mod;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof a);
        memset(flag,0,sizeof flag);
        memset(use,0,sizeof use);
        memset(vis,0,sizeof vis);
        cnt = maxn = 0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",s);
            len = strlen(s);
            if(len>1)
                flag[s[0]-'a'] = 1;
            maxn = max(maxn,len+10);
            for(int j=len-1;j>=0;j--)
            {
                int c = s[j] - 'a';
                a[c].letter = c;
                if(!vis[c])
                    cnt++,vis[c]=1;
                a[c].num[len-1-j]++;
                if(a[c].num[len-1-j]>=26)
                {
                    a[c].num[len-j]+=a[c].num[len-1-j]/26;
                    a[c].num[len-1-j]%=26;
                }
                int pos = len - j;
                while(a[c].num[pos]>=26)
                {
                    a[c].num[pos+1]+=a[c].num[pos]/26;
                    a[c].num[pos]%=26;
                    pos++;
                }
            }
        }
        sort(a,a+26,cmp);
        if(cnt==26)
        {
            for(int i=cnt-1;i>=0;i--)
            {
                if(flag[a[i].letter])
                    continue;
                use[i] = 1;
                break;
            }
        }
        int now = 25;
        ll ans = 0;
        for(int i=0;i<cnt;i++)
        {
            if(use[i])
                continue;
            for(int j=0;j<=maxn;j++)
            {
                ans = (ans + now * a[i].num[j] * add[j]) % mod;
            }
            now--;
        }
        printf("Case #%d: %lld\n",++cas,ans);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值