Balala Power!

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3555    Accepted Submission(s): 844

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 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 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. (1≤n≤100000)

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 #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
1
a
2
aa
bb
3
a
ba
abc
 
Sample Output
Case #1: 25
Case #2: 1323
Case #3: 18221
 
Source
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6044 6043 6042 6041 6040 
 
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<bits/stdc++.h> using namespace std;
const long long mod=1e9+;
struct node
{
int id;
double k;
}a[];
int b[];
long long num[][];
bool vis[];
char ch[];
int n,maxlen; bool cmp(node a,node b)
{
return a.k>b.k;
}
int main()
{
int cas=;
while(~scanf("%d",&n))
{
maxlen=;
memset(num,,sizeof(num));
memset(vis,,sizeof(vis));
for(;n>;n--)
{
scanf("%s",&ch);
int l=strlen(ch);
maxlen=max(maxlen,l);
if (l>) vis[ch[]-'a']=;
for(int i=;i<l;i++)
num[ch[i]-'a'][l-i-]++;
} for(int i=;i<;i++)
{
a[i].id=i; a[i].k=;
for(int j=;j<maxlen;j++)
a[i].k=a[i].k/+num[i][j];
} sort(a,a+,cmp); for(int i=;i>=;i--)
{
if (vis[a[i].id]) continue;
else
{
int cnt=;
for(int j=;j<;j++)
if (j!=i) b[a[j].id]=cnt--;
else b[a[j].id]=;
break;
}
} long long ans=;
for(int i=;i<;i++)
{
long long ret=;
for(int j=;j<maxlen;j++)
{
ans=(ans+num[i][j]*ret*b[i])%mod;
ret=(ret*)%mod;
}
}
printf("Case #%d: %lld\n",++cas,ans);
}
return ;
}

hdu 6034 Balala Power!的更多相关文章

  1. HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1

    /* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...

  2. 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 ...

  3. HDU 6034 Balala Power!(贪心+排序)

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  4. 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  5. HDU 6034 Balala Power!【排序/进制思维】

    Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java ...

  6. 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 wi ...

  7. HDU 6034 Balala Power! (贪心+坑题)

    题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...

  8. 6034 Balala Power! (17多校)

    题目大意:给出的字符串,每个字符建立一种与0-25的对应关系.然后每个字符串看成是一个26进制的数.问能获得的数的总和的最大值.(最后对1e9+7取模). 题目思考:把每个字符的贡献值看做一个26进制 ...

  9. hdu 6034 B - Balala Power! 贪心

    B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...

随机推荐

  1. NGUI混合FingerGesture《卷二》分离触摸事件

    背景 在使用NGUI按钮组件的时候,点击按钮同时触发FingerGesture的Touch事件, 通俗点讲,NGUI点击之后,点击事件被FingerGesture又执行了一遍. 解决思路 持有一个全局 ...

  2. How can For each...

    Answer:   I understand the IEnumerator/IEnumerable methods and properties and also how they are inte ...

  3. Twitter的分布式自增ID算法snowflake

    snowflake 分布式场景下获取自增id git:https://github.com/twitter/snowflake 解读: http://www.cnblogs.com/relucent/ ...

  4. webmagic的设计机制及原理-如何开发一个Java爬虫 转

    此文章是webmagic 0.1.0版的设计手册,后续版本的入门及用户手册请看这里:https://github.com/code4craft/webmagic/blob/master/user-ma ...

  5. 20145313张雪纯 《Java程序设计》第5周学习总结

    20145313张雪纯 <Java程序设计>第5周学习总结 教材学习内容总结 JAVA中所有错误都会被打包成对象,可以用尝试(try)捕捉(catch)代表错误的对象后做一些处理.使用tr ...

  6. 蓝桥杯练习——C++输出阶乘的最右边一位非零数

    #include<iostream> #include<iomanip> using namespace std; #define M 10000 #define N 1000 ...

  7. Numpy学习1

    NumPy学习(1) 参考资料: http://www.cnblogs.com/zhanghaohong/p/4854858.html http://linusp.github.io/2016/02/ ...

  8. HighCharts 在IE8下饼图不显示的问题

    HighCharts饼图用来做数据统计时,在IE8下发现某些图形不能正确显示出来. 在IE8下面会报  'this.renderer.gradients' 为空或不是对象 这样的错误.. 解决方法: ...

  9. centos7 VNC安装

    root用户: yum install tigervnc-server .service vim /etc/systemd/system/vncserver@:.service .service vn ...

  10. Memcached prepend 命令

    Memcached prepend 命令用于向已存在 key(键) 的 value(数据值) 前面追加数据 . 语法: prepend 命令的基本语法格式如下: prepend key flags e ...