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. JVM(3) 垃圾回收器与内存分配策略

    文章内容摘自:深入理解java虚拟机 第三章   对象已死? 1. 引用计数算法: 给对象中添加一个引用计数器,每当有一个地方引用它时,计数器值就加1:当引用失效时,计数器值就减1:任何时刻计数器为0 ...

  2. 【Linux学习】3.Linux常见配置文件

    一./etc 配置文件/etc/passwd 用户数据库,其中的域给出了用户名.真实姓名.家目录.加密口令和用户的其他信息 /etc/group 类似/etc/passwd ,但说明的不是用户而是组. ...

  3. python单元测试框架——pytest

    官网:https://docs.pytest.org/en/latest/ pytest帮你写出更好的程序 1.An example of a simple test:(一个简单的例子),命名为tes ...

  4. Eclipse安装Activiti插件(流程设计器)

    Eclipse安装Activiti插件(流程设计器) 一.安装步骤: 1,打开Eclipse的 Help -> Install New Software,填上插件地址: Name:Activit ...

  5. idea+maven本地仓库更新问题

    在POM文件中将dependecy填好,.m2/repository/文件夹下也有相应的包下载了.但idea External Libraries就是引用不到这个包. 怎么mvn clean inst ...

  6. 20145328 《Java程序设计》实验四实验报告

    20145328 <Java程序设计>实验四实验报告 实验名称 Andoid开发基础 实验内容 基于Android Studio开发简单的Android应用并部署测试; 了解Android ...

  7. 20135302魏静静——linux课程第五周实验及总结

    linux课程第五周实验及总结 一.学习总结 给MenuOS增加time和time-asm命令(四步操作命令) rm menu -rf 强制删除git clone http://github.com/ ...

  8. Spring笔记(二)

    1. SPRING aop入门 Aop  面向切面编程 在一个大型的系统中,会写很多的业务类--业务方法 同时,一个大型的系统中,还有很多公共的功能:比如事务管理.日志处理.缓存处理..... 1.1 ...

  9. IntelliJ IDEA 开发git多模块项目

    1.clone主项目 填写主仓库地址 2.在项目根目录,初始化子模块,并clone源码 git submodule init git submodule update 3.定位到各个子模块根目录,并切 ...

  10. Elasticsearch之几个重要的分词器

    前提 什么是倒排索引? Elasticsearch之分词器的作用 Elasticsearch之分词器的工作流程 Elasticsearch之停用词 Elasticsearch之中文分词器 Elasti ...