博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Balala Power!(大数+思维)
阅读量:7090 次
发布时间:2019-06-28

本文共 3533 字,大约阅读时间需要 11 分钟。

Balala Power!

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 714    Accepted Submission(s): 117

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 froma 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
 
//题意:有 n 个小写的字符串,想要把它们变为 26 进制的 0-25 的数字,问 n 个数最大的和为多少?还有,不能有前导0,除非就是0
 
题解:每个字母,在任意位置都会有个权值,统计所有字母的权值,但是只能用大数保存,保存完后。按字母权值排序,最大的赋 24 ,类推,然后考虑可能前导 0 的情况,如果,找到不会作为前导的数后,,关键是,不能交换,而是整体向上平移 1 ,这样才能保证是最大值
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 #define LL long long 7 #define MOD 1000000007 8 #define MX 100100 9 10 int n; 11 int al_n[26]; 12 LL num[26][MX]; 13 LL quan[26]; 14 char temp[MX]; 15 bool ok[26]; 16 17 bool cmp(int a,int b) 18 { 19 if (al_n[a]!=al_n[b]) 20 return al_n[a]>al_n[b]; 21 22 for (int i=al_n[a];i>=0;i--) 23 if (num[a][i]!=num[b][i]) 24 return num[a][i]>num[b][i]; 25 26 return 0; 27 } 28 29 int main() 30 { 31 int cnt=1; 32 while (scanf("%d",&n)!=EOF) 33 { 34 memset(quan,0,sizeof(quan)); 35 memset(num,0,sizeof(num)); 36 memset(ok,0,sizeof(ok)); 37 38 for (int i=0;i
=0;j--) 44 { 45 num[temp[j]-'a'][k]++; 46 k++; 47 } 48 if (len!=1) 49 ok[temp[0]-'a']=1; 50 } 51 52 for (int i=0;i<26;i++)//字母 53 { 54 al_n[i]=0; 55 for (int j=1;j
=26) 59 { 60 int jin = num[i][j]/26; 61 num[i][j+1]+=jin; 62 num[i][j]%=26; 63 } 64 } 65 } 66 67 int alpa[26]; 68 for (int i=0;i<26;i++) alpa[i]=i; 69 sort(alpa,alpa+26,cmp); 70 71 if (al_n[alpa[25]]!=0&&ok[alpa[25]]==1) 72 { 73 for (int i=25;i>=0;i--) 74 { 75 if (ok[alpa[i]]==0) 76 { 77 int sbsb=alpa[i]; 78 for (int j=i+1;j<=25;j++) 79 alpa[j-1]=alpa[j]; 80 alpa[25]=sbsb; 81 break; 82 } 83 } 84 } 85 86 LL ans = 0; 87 LL qqq = 25; 88 for (int i=0;i<26;i++) 89 { 90 int zimu = alpa[i]; 91 if (al_n[zimu]==0) continue; 92 LL tp=qqq; 93 for (int j=1;j<=al_n[zimu];j++) 94 { 95 ans = (ans + (tp * num[zimu][j])%MOD)%MOD; 96 tp=(tp*26)%MOD; 97 } 98 qqq--; 99 }100 printf("Case #%d: %lld\n",cnt++,ans);101 }102 return 0;103 }
View Code

 

转载于:https://www.cnblogs.com/haoabcd2010/p/7236214.html

你可能感兴趣的文章
gitlab ssh key
查看>>
克隆虚拟机导致Linux无法启动网卡的分析与解决
查看>>
[VBS]自动加域并将计算机移至指定OU
查看>>
随机数去重
查看>>
如何从mac下的photos导出照片
查看>>
Error Code:1153 Got a packet bigger than ‘max_a...
查看>>
NCRE考试感想 三级信息安全(下)
查看>>
Java记录 -81- EnumSet和EnumMap
查看>>
我的友情链接
查看>>
张鹏 轻松学习网页设计 第03讲 html段落与标题文字!
查看>>
服务器节能
查看>>
多年收集的一些稀有软件1
查看>>
Deduplication去重算法基础之可变长度数据分片
查看>>
MyBatis学习总结(5)——实现关联表查询
查看>>
Java基础学习总结(5)——多态
查看>>
Greenplum同步到Oracle脚本
查看>>
Tomcat 不同端口配置两个应用程序
查看>>
XMLDecoder反序列化漏洞
查看>>
【.net web】Response.Redirect 打开新窗口的两种方法
查看>>
多从库时半同步复制不工作的BUG分析
查看>>