HDU 6034 Balala Power! (位权排序)
2017-12-08 11:42
323 查看
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 6884 Accepted Submission(s): 1705
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. (1≤n≤100000)
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个串,每个字母都代表一个数字(从0到25),每个串都是基于26进制下的一个数,问这些串的和的最大值,并以10进制输出
思路
因为一个串最长也就100000位,所以我们可以用一个数组来存这个字母在这一位上出现的次数,然后再用sort进行排序,排序的时候从所给的串的最长长度开始一直往下比,也就是数据中的最大位权,若两个字母中位值不同就返回较大的,还有一个坑点就是不能出现前导零,我们再开一个数组来记录一下长度不为1的串第一个的字母,排完序后从最后一个开始找未出现在开头的字符,给他为0,之后的字母代表的值都加1
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> const int mod=1000000007; using namespace std; const int maxn=100005; int maxl; long long m[maxn]; int vis[27]; struct node { int flag; int num[maxn]; }ch[26]; bool cmp(node a,node b) { for(int i=maxl+4;i>0;i--) { if(a.num[i]!=b.num[i]) { return a.num[i]>b.num[i]; } else ; } return a.num[0]>b.num[0]; } void inti() { memset(m,0,sizeof(m)); long long now=1; m[0]=1; for(int i=1;i<maxn;i++) { now*=26; m[i]=now%mod; now%=mod; } } int main() { freopen("1002.in","r",stdin); freopen("a","w",stdout); int cas=1; int n; inti(); while(scanf("%d",&n)!=EOF) { maxl=0; memset(ch,0,sizeof(ch)); memset(vis,0,sizeof(vis)); for(int i=0;i<26;i++) { ch[i].flag=i; } for(int i=0;i<n;i++) { char str[maxn]; scanf("%s",str); int len=strlen(str); maxl=max(len,maxl); if(len!=1) vis[str[0]-'a']=1; for(int j=0;j<len;j++) { int x=str[j]-'a'; int y=len-j-1; ch[x].num[y]++; if(ch[x].num[y]==26) { ch[x].num[y++]=0; ch[x].num[y]++; } } } sort(ch,ch+26,cmp); long long ans=0; int flag=-1; for(int i=25;i>=0;i--) { if(!vis[ch[i].flag]) { flag=i; break; } } for(int i=0;i<26;i++) { if(i==flag); else if(i<flag) { long long haha=25-i; for(int j=maxl+4;j>=0;j--) { ans+=haha*m[j]*ch[i].num[j]; ans%=mod; } } else { long long haha=25-i+1; for(int j=maxl+4;j>=0;j--) { ans+=haha*m[j]*ch[i].num[j]; ans%=mod; } } } printf("Case #%d: ",cas++); printf("%lld\n",ans); } return 0; }
相关文章推荐
- HDU 2017 多校联合训练赛1 1002 6034 Balala Power 排序
- HDU 6034 17多校1 Balala Power!(思维 排序)
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
- HDU 6034 Balala Power! 排序 贪心
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- HDU 6034 Balala Power! 【模拟】【大数高精度】
- HDU 6034 Balala Power!
- HDU 6034 Balala Power!(贪心)
- HDU 6034 Balala Power!(多校1)
- Balala Power! HDU - 6034 多校1
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
- HDU 6034 Balala Power!(贪心)
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- HDU 6034 Balala Power! 2017多校1.2
- HDU 6034 Balala Power!(贪心)
- 第一场 hdu 6034 Balala Power!
- hdu 6034 Balala Power!
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- hdu 6034 Balala Power! (2017 Multi-University Training Contest - Team 1)