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. Submine Text 快捷键

    Ctrl+Shift+P:打开命令面板 Ctrl+P:搜索项目中的文件 Ctrl+G:跳转到第几行 Ctrl+W:关闭当前打开文件 Ctrl+Shift+W:关闭所有打开文件 Ctrl+Shift+V ...

  2. Spring 事务管理tx,aop

    spring tx:advice事务配置 2016年12月21日 17:27:22 阅读数:7629 http://www.cnblogs.com/rushoooooo/archive/2011/08 ...

  3. JVM 内存知识总结

    本文主要参考内容: http://hllvm.group.iteye.com/group/wiki/3053-JVM http://my.oschina.net/xishuixixia/blog/13 ...

  4. linux上使用wget下载文件

    首次安装的centos操作系统是没有安装wget的,所以首先需要先安装wget,然后才能使用wget下载文件. 1.第一步,保证centos能正常连网.使用命令  :yum -y install wg ...

  5. linux性能分析命令1:top命令

    转载:http://www.cnblogs.com/peida/archive/2012/12/24/2831353.html top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的 ...

  6. git删除本地分支和删除远程分支

    引言: 切换分支的时候命令打错了,git checkout 后面没有跟分支名,结果git status,很多delete的文件,直接冒冷汗,git add ,commit 之后发现本地与远程确实是删除 ...

  7. thinkerCMS是一款thinkphp写的微型cms框架可以参考下

    http://www.thinkphp.cn/code/1764.html                       thinkphp官网thinkercms介绍 http://cms.thinke ...

  8. ElasticSearch(四) ElasticSearch中文分词插件IK的简单测试

    先来一个简单的测试 # curl -XPOST "http://192.168.9.155:9200/_analyze?analyzer=standard&pretty" ...

  9. WCF基本知识

    1.开通WCF调试服务: 须在服务端的行为中作如下配置:includeExceptionDetailInFaults="true" 代码如下: <behaviors> ...

  10. Spring笔记1——Spring起源及其核心技术

    Spring的作用 当我们使用一种技术时,需要思考为什么要使用这门技术.而我们为什么要使用Spring呢?从表面上面SSH这三大框架中,Struts是负责MVC责任的分离,并且提供为Web层提供诸如控 ...