Balala Power!【排序/进制思维】

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

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
 
【题意】:给出n个字符串,对于字符a~z,赋值0~25,求在26进制下的最大值。
【分析】:

二十六进制即为用二十六个字母替代从0到25的二十六个数字,与二进制,八进制,十进制,十六进制一样,二十六进制也可与其它进制法互相转换。
举例
例1:二十六进制转换为十进制过程。
以GWW为例,则为G(6)*26^2+W(22)*26^1+W(22)*26^0=4650
结果即为4650

注明:一般的二十六进制字母序数为:
A=0,Z=25
或A=1,Z=0
//官方:每个字符对答案的贡献都可以看作一个 26 进制的数字,问题相当于要给这些贡献加一个 0 到 25 的权重使得答案最大。最大的数匹配 25,次大的数匹配 24···依次类推。

//题目要求字符串代表的26进制数之和最大,就要将高权值尽可能地赋给26进制数中在高位出现频率更高的字母,这样,问题就分成了三部分。第一,字母按价值排序;第二,字母赋值;第三,求和。

第一步,排序问题,为了方便比较,我们建立一个26*100000的数表,记录每个字母在每一位上的出现频数,从高位开始比较出现频数最高的字母赋值为25。在这里要注意到,因为有些字母可能会在某一位出现若干多次(超过26),这样该字母在本位上的价值可能会超过更高位上的字母价值,因此,我们运用数制进位的思想,将出现频数超过26的字母向上进位,这样就保证了在高位字母价值的绝对优势。在比赛时手动进行了字母排序,不仅耗费了大量的精力,而且最终超时了。赛后看标程,才深深地体会到cmp函数的神奇。

第二步,排序完成后,字母们整齐的码在一维数组里。按价值由高到低赋值即可。但是,还要注意前导0的问题,出现在字符串首的字母是不能被赋值为0的,在这里我们将价值最低且没有出现在字符串首的字母标记出来。然后将剩余的字母按价值赋值。

第三步,求和。即26进制转10进制。我的方法和标程略有差别,标程引入了sum[ ]数组,但是时间复杂度貌似差别不大,

另外,还有一些小细节。
.计算26^n,用打表代替快速幂取模,可以大大降低时间复杂度
.由于进位的问题,在字符串比较和进制转化时,注意要比最长字符串的长度ml再多比较一位。

题解

【代码】:
 

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! —— Multi-University Training 1

    Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them wi ...

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

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

  7. hdu 6034 Balala Power!

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

  8. HDU 4278 Faulty Odometer 8进制转10进制

    Faulty Odometer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  9. HDU 1335 Basically Speaking(进制转换)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335 Problem Description The Really Neato Calculator ...

随机推荐

  1. 剑指Offer - 九度1522 - 包含min函数的栈

    剑指Offer - 九度1522 - 包含min函数的栈2013-12-01 23:44 题目描述: 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数. 输入: 输入可能包含多个测 ...

  2. 【Kernal Support Vector Machine】林轩田机器学习技术

    考虑dual SVM 问题:如果对原输入变量做了non-linear transform,那么在二次规划计算Q矩阵的时候,就面临着:先做转换,再做内积:如果转换后的项数很多(如100次多项式转换),那 ...

  3. Python学习-前台开发-JavaScript、Dom和jQuery

    JavaScript JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. ...

  4. 孤荷凌寒自学python第五天初识python的列表

    孤荷凌寒自学python第五天 列表 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 粗俗地区分列表,可以这样理解,定义或print列表后显示时,列表中的各元素都是用一个方括号[]括起来的. ...

  5. mongodb 部署

    安装mongodb-3.4 1)将安装包上传至服务器 2)对压缩文件进行解压 tar -zxvf mongodb-linux-x86_64-suse12-v3.4-latest.tar.gz 3)把解 ...

  6. Sublime Text 2 中文乱码

    欲解决乱码问题,关键在于让Sublime Text 2支持GB2312和GBK.步骤如下:1.安装Sublime Package Control.在Sublime Text 2上用Ctrl+-打开控制 ...

  7. 哈希UVALive 6326 Contest Hall Preparation

                              Encrypting passwords is one of the most important problems nowadays, and y ...

  8. Oracle 数据库导出时 EXP-00008;ORA-00904

    问题是客户端和服务器端版本问题,我本地是11g,而服务器端是10g. 规则1:低版本的exp/imp可以连接到高版本(或同版本)的数据库服务器,但高版本的exp/imp不能连接到低版本的数据库服务器. ...

  9. C#中不用安装Oracle客户端连接Oracle数据库(转)

    原文地址:http://www.cnblogs.com/jiangguang/archive/2013/02/19/2916882.html 0.首先,从Oracle网站上下载对应版本的Oracle ...

  10. [CF1036C]Classy Numbers

    题目大意:多个询问,每个询问问$[l,r](1\leqslant l\leqslant r\leqslant10^{18})$内有多少个数满足非零数位小于等于$3$. 题解:数位$DP$,$f_{i, ...