【多校训练】hdu 6034 Balala Power!
来源:互联网 发布:淘宝联如何设置推广位 编辑:程序博客网 时间:2024/06/05 10:14
Problem Description
Talented Mr.Tang has
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
Input
The input contains multiple test cases.
For each test case, the first line contains one positive integersn , the number of strings. (1≤n≤100000)
Each of the nextn lines contains a string si consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤106)
For each test case, the first line contains one positive integers
Each of the next
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
1a2aabb3abaabc
Sample Output
Case #1: 25Case #2: 1323Case #3: 18221
题意:
给你n个字符串,给26个字母赋值0-25,使字符串的和最大,不能有前导0,求最大值。
思路:
可以统计下每个字母的权重,权重最大的字母赋值为25,,以此类推。要让非首字母且权重相对较小的字母为0。
//// main.cpp// 1002//// Created by zc on 2017/7/25.// Copyright © 2017年 zc. All rights reserved.//#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>#define ll long longusing namespace std;const ll MOD=1e9+7;char s[120000];int a[27][120000];int b[27],c[27],e[27];ll d[120000];bool cmp(int x,int y){ for(int i=110000;i>=0;i--) { if(a[x][i]!=a[y][i]) return a[x][i]<a[y][i]; } return 0;}int main(int argc, const char * argv[]) { int n,kase=0; d[1]=1; for(int i=2;i<=110000;i++) d[i]=(d[i-1]*26)%MOD; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); memset(e,0,sizeof(e)); for(int i=0;i<n;i++) { scanf("%s",s); int len=strlen(s); for(int j=len-1;j>=0;j--) { a[s[j]-'a'][len-j]++; if(j==0) e[s[j]-'a']=1; } } for(int i=0;i<26;i++) { for(int j=1;j<=110000;j++) { if(a[i][j]>26) { a[i][j+1]+=a[i][j]/26; a[i][j]%=26; } } } for(int i=0;i<26;i++) b[i]=i; sort(b,b+26,cmp); if(e[b[0]]==1) { int t=1; while(t<26&&e[b[t]]==1) t++; int tt=b[t]; for(int i=t-1;i>=0;i--) b[i+1]=b[i]; b[0]=tt; } for(int i=0;i<26;i++) c[b[i]]=i; ll ans=0; for(int i=0;i<=26;i++) { for(int j=1;j<=110000;j++) { ans=(ans+c[i]*a[i][j]*d[j])%MOD; } } printf("Case #%d: %lld\n",++kase,ans); }}
阅读全文
0 0
- 【多校训练】hdu 6034 Balala Power!
- 2017 多校训练第一场 HDU 6034 Balala Power!
- HDU-2017 多校训练赛1-1002-Balala Power!
- HDU 6043 (2017 多校训练赛1 1002) Balala Power!
- HDU-6034 Balala Power!
- [HDU]-6034 Balala Power!
- HDU 6034 Balala Power!
- hdu 6034 Balala Power!
- 【HDU 6034 Balala Power!】
- hdu 6034 Balala Power!
- HDU 6034 Balala Power!
- HDU 6034 Balala Power!
- hdu-6034-Balala Power!
- HDU-6034 Balala Power!
- hdu-6034-Balala Power!
- HDU 6034 Balala Power!
- HDU 6034 Balala Power!
- hdu 6034 Balala Power!
- Android体系总结
- docker--制作自己的镜像(二)
- HDU 6035 Colorful Tree dfs
- xhr获取二进制数据方法
- LintCode之矩阵面积
- 【多校训练】hdu 6034 Balala Power!
- More is better --并查集
- pc网站qq互联登录授权php版
- LeetCode——617. Merge Two Binary Trees(递归,C++)
- HDU1232 畅通工程
- C++浅拷贝实例
- php 高效率写法 推荐
- PS学习笔记-----钢笔工具
- 分布式HTAP数据库PetaData:大数据行业带来的新变化