HDU 6034 Balala Power!
来源:互联网 发布:kettle java代码 编辑:程序博客网 时间:2024/05/24 01:42
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2145 Accepted Submission(s): 398
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
Source
2017 Multi-University Training Contest - Team 1
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;const int maxn = 2e5+10;const LL MOD = 1e9+7;int N,vist[30],level[30];int Map[30][maxn];int Max;char str[maxn];struct node{ char st[maxn]; int id;}nxt[30];bool cmp(node a,node b){ return strcmp(a.st,b.st)>0;}int main(){ int cas = 0; while(~scanf("%d",&N)){ memset(Map,0,sizeof(Map)); memset(vist,0,sizeof(vist)); Max = 0; while(N--){ scanf("%s",str); int len = strlen(str); Max = max(Max,len); for(int i = 0; i < len; i++) Map[str[i]-'a'][len-i-1]++; if(len > 1) vist[str[0]-'a'] = 1; } Max += 10000;//继续向上进位 for(int i = 0; i < 26; i++){ for(int j = 0; j < Max; j++){ Map[i][j+1] += Map[i][j]/26; Map[i][j] %= 26; nxt[i].st[Max-j-1] = Map[i][j]+'a'; } nxt[i].id = i; } sort(nxt,nxt+26,cmp); for(int i = 0; i < 26; i++){ level[nxt[i].id] = 25-i; } int t = 25; while(vist[nxt[t].id] && t){//获取替换是最小代价 swap(level[nxt[t].id],level[nxt[t-1].id]); t--; } LL ans,res; ans = 0; for(int i = 0; i < 26; i++){ res = 0; for(int j = 0; j < Max; j++){ res = res*26+(nxt[i].st[j]-'a')*level[nxt[i].id]; res %= MOD; } ans += res; ans %= MOD; } printf("Case #%d: %lld\n",++cas,ans); } return 0;}
阅读全文
0 1
- 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!
- hdu 6034 Balala Power!(贪心)
- HDU 6034 Balala Power!(进制)
- HDU 6034 Balala Power!【贪心】
- HDU 6034 Balala Power!【贪心】
- 希尔排序
- equals使用和重写
- test
- Hive
- Android机用移动数据流量获取也能获取mac地址的终极方法。(第二种方法)
- HDU 6034 Balala Power!
- 4 Values whose Sum is 0 --CSU-ACM2017暑假集训2-二分搜索
- hdu 1166 敌兵布阵【入门线段树 & 树状数组】
- 选择排序
- 《如何管理程序猿》
- bzoj3545[ONTAK2010]Peaks 线段树合并+离散
- LeetCode 599. Minimum Index Sum of Two Lists
- oracle 数据库 练习题2
- @font-face属性参数详细介绍