HDU 6034 Balala Power! —— Multi-University Training 1

Talented Mr.Tang has nn 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 2626 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+7109+7.
Input
The input contains multiple test cases.
Output
For each test case, the first line contains one positive integers nn, the number of strings. (1≤n≤100000)
Each of the next nn lines contains a string sisi consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤1e6)e
OutputFor each test case, output " Case #xx: yy" in one line (without quotes), where xxindicates the case number starting from 11 and yy 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
题目大意:用26个字母表示26进制数中的1~26,并且给你n个字符串,以26进制从字符串转化为数字,问这些数字之和最大能有多少(以十进制输出)。为保证数据正确,其中必存在至少一个字母是代表了0。
思路:模拟。首先每个字母代表的数未知,但由于每个字符在字符串的位置是已知的,我们就可以求出每个字母从26进制转化十进制时的“系数”(即像26^a1+26^a2+26^a3……的数),用数组存储26进制数,在求和时考虑进位,去掉必为0的字母,然后对按26进制数的大小对数组排序,最后就能够求和解出答案了。。。比赛的时候是用的字符串存26进制,理论上也是可以做的,但是因为进位的姿势不对(一边加一边进位,先全部加完再进位才是正确的)导致TLE/(ㄒoㄒ)/
代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
#define MOD 1000000007
#define MAXN 100010
using namespace std;
long long num[][MAXN],w[];
long long sum[];
long long a[MAXN];
int u;
char ss[MAXN];
bool vis[];
bool cmp(int s, int t)
{
for(int i=u-;i>=;i--){
if(num[s][i]!=num[t][i])
return num[s][i]<num[t][i];
}
return ;
}
int main()
{
a[]=;
for(int i=;i<MAXN-;i++)
a[i]=*a[i-]%MOD; int n;
int z=;
while(~scanf("%d", &n))
{
u=;
memset(num, , sizeof(num));
memset(sum, , sizeof(sum));
memset(vis,false,sizeof(vis));
int wei,p;
for(int i=;i<n;i++){
scanf("%s", ss);
int l=strlen(ss);
if(l>)
vis[ss[]-'a']=true; for(int j=;j<l;j++){
p=ss[j]-'a';
wei=l--j;
num[p][l--j]++;
sum[p]+=a[wei];
sum[p]%=MOD;
}
u=max(u, l);
}
for(int i=;i<;i++){
for(int j=;j<u;j++){
num[i][j+]=num[i][j+]+num[i][j]/;
num[i][j]=num[i][j]%;
}
while(num[i][u])
{
num[i][u+]+=num[i][u]/;
num[i][u++]%=;
u++;
}
w[i]=i;
}
int cnt=-;
sort(w, w+, cmp);
for(int i=;i<;i++){
if(!vis[w[i]]){
cnt=w[i];
break;
}
}
//cout<<cnt<<endl;
int res=,x=;
for(int i=;i>=;i--){
if(cnt!=w[i]){
res+=(long long)(x--)*sum[w[i]]%MOD;
res%=MOD;
} }
z=z+;
printf("Case #%d: %lld\n",z,res);
}
}
HDU 6034 Balala Power! —— Multi-University Training 1的更多相关文章
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- hdu 6034 Balala Power!
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- HDU 6034 Balala Power!【排序/进制思维】
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java ...
- HDU 6034 Balala Power! (贪心+坑题)
题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...
- 6034 Balala Power! (17多校)
题目大意:给出的字符串,每个字符建立一种与0-25的对应关系.然后每个字符串看成是一个26进制的数.问能获得的数的总和的最大值.(最后对1e9+7取模). 题目思考:把每个字符的贡献值看做一个26进制 ...
- hdu 6034 B - Balala Power! 贪心
B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...
随机推荐
- centos mysql初探 -- 配置、基本操作及问题
目录: centos安装mysql 使用mysql客户端进行简单操作 python2和python3连接mysql mysql导入文件问题 死锁解决办法 windows 7 远程连接 mysql 服务 ...
- 在Mac OS X 10.11 EI Capitan 中提取iso镜像
到Apple store上下载最新的OS X El Capitan ,下载完成后就可以进行iso镜像提取操作了. 步骤一:挂载El Capitan 的安装镜像文件 1 hdiutil attach / ...
- linux-批量修改目录下后缀shell
#!/bin/bashcd /optrename .sh .shell *.shecho "后缀修改成功"
- C. Roads in Berland
题目链接: http://codeforces.com/problemset/problem/25/C 题意: 给一个最初的所有点与点之间的最短距离的矩阵.然后向图里加边,原有的边不变,问加边后的各个 ...
- jmeter设置全局变量token
返回登录后的token使用json path Extractor插件,定位到获取后的token为变量 在登录下后置处理器下添加json path Extracto插件 根据上面获取到的token位置路 ...
- php有几种开发语言
php有几种开发语言? php的启发语言有五种,分别是C.Perl.Java.C++.Python. PHP(全称:PHP:Hypertext Preprocessor,即“PHP:超文本预处理器”) ...
- vue2.0中router-link详解
vue2.0中router-link详解:https://blog.csdn.net/lhjuejiang/article/details/81082090 在vue2.0中,原来的v-link指令已 ...
- 06 CAS的原理和AQS
CAS的原理 CAS(compareAndSwap),比较交换,是一种无锁的原子算法. Cas(value,expect,newValue),如果vaule和ecpect一样,就更新为newValue ...
- [LeetCode] Linked List Cycle II, Solution
Question : Given a linked list, return the node where the cycle begins. If there is no cycle, return ...
- JS 自定义样式格式化日期
Date.prototype.format = function (fmt) { var o = { "M+": this. ...