hdu6034
来源:互联网 发布:有什么看书软件 编辑:程序博客网 时间:2024/05/22 07:53
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 3544 Accepted Submission(s): 838
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思路:在多校联赛上一直没有做出来,后面清题时才发现如果直接存权值的话long long int根本不够用,如果把权值直接取模的话,那么就会影响后面的赋值,因此需要开一个二维数组来记录权值,a[i][j]代表第i个字母在j位置出现可了多少次,这是26进制的,所以满26向前面进一位,一开始用结构体做,结果TLE了,后面发现用多个数组进行排序其实更快。其实,一个数组可以通过另一个数组来排序。代码:#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <cmath>const long long int MOD=1e9+7;using namespace std;long long int poww(int n,int m){ long long int a=1; while(m) { if(m&1)a=(a*n)%MOD; n=(n*n)%MOD; m>>=1; }}int a[27][100020];int flag[27];int v[27];int ss[27];bool cmp(int x,int y){ int i; for(i=100019;i>=0;i--) { if(a[x][i]>a[y][i])return true; if(a[x][i]<a[y][i])return false; } return false;}int main(){ int m; int sss=1; while(scanf("%d",&m)!=EOF) { int i; memset(a,0,sizeof(a)); memset(flag,0,sizeof(flag)); memset(ss,0,sizeof(ss)); memset(v,-1,sizeof(v)); char c[100005]; for(i=0;i<m;i++) { scanf("%s",c); int n=strlen(c); if(n>1)flag[c[0]-'a'+1]=1; for(int j=0;j<n;j++) { a[c[j]-'a'+1][n-j-1]++; } } for(i=1;i<=26;i++) { for(int j=0;j<100020;j++) { if(a[i][j]>=26) { a[i][j+1]+=a[i][j]/26; a[i][j]%=26; } } } int s[27]; for(i=1;i<=26;i++) { s[i]=i; } sort(s+1,s+1+26,cmp); int k=25; for(i=26;i>=1;i--) { if(flag[s[i]]!=1) { v[s[i]]=0; break; } } for(i=1;i<=26;i++) { int x=s[i]; if(v[x]==-1) { v[x]=k--; } } long long int ans=0; long long int e=1; for(i=0;i<100020;i++) { for(int j=1;j<=26;j++) { ans=(ans+((e*a[j][i])%MOD*v[j])%MOD)%MOD; } e*=26; e%=MOD; } printf("Case #%d: %lld\n",sss++,ans); } return 0;}
阅读全文
0 0
- hdu6034
- hdu6034
- hdu6034
- hdu6034-贪心
- HDU6034【模拟】
- HDU6034 Balala Power! [贪心]
- HDU6034-Balala Power! 贪心
- hdu6034 Balala Power! 贪心
- HDU6034 Balala Power! (字符串)
- HDU6034-Balala Power!
- HDU6034 Balala Power!【贪心】
- hdu6034(Balala Power!)
- HDU6034-Balala Power-模拟
- HDU6034-Balala Power!
- hdu6034 Balala Power!
- hdu6034--Balala Power!
- hdu6034(Balala Power!)
- HDU6034 Balala Power!
- 神奇的口袋(百练2755)
- 中断-timer0
- Android_Service的生命周期(服务)
- php返回当前日期或者指定日期是周几
- Polya定理及应用
- hdu6034
- 多重背包
- HDU 6002 Game Leader(贪心)
- 圣典百科这个中文API真是厉害了 关于LayerMask 层蒙版的中文解释
- 获取下拉列表选中项的文本值包含\r\n
- Linux学习-Bash数据流重定向
- 移动APP:前端测试 弱网测试方法整理
- lintcode--不同的子序列
- HDU1229还是A+B