B - Balala Power!

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=6034

题面描述

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.

输入

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)

输出

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.

样例输入

1

a

2

aa

bb

3

a

ba

abc

样例输出

Case #1: 25

Case #2: 1323

Case #3: 18221

题意

给你n个由26个字母组成的字符串,你现在要给每个字母用[0,25]赋值,不能要求有前导0,每个值对应一个字母.

要求使得字符串组成的数字和最大。

题解

直接算每个字母的贡献,然后赋值就行,把0给最小的合法的字母即可。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int mod = 1e9+7;
struct node{
int len[maxn];
int w;
int v;
int L;
}p[26];
int n;
string s[maxn];
int flag[26];
int cas = 0;
bool cmp(node A,node B){
if(A.L!=B.L)return A.L<B.L;
for(int i=A.L;i>=0;i--){
if(A.len[i]==B.len[i])continue;
return A.len[i]<B.len[i];
}
return 0;
}
int main(){
while(cin>>n){
cas++;
memset(flag,0,sizeof(flag));
for(int i=0;i<26;i++){
for(int j=0;j<=p[i].L;j++){
p[i].len[j]=0;
}
}
for(int i=0;i<26;i++){
p[i].v=0;
p[i].w=i;
p[i].L=-1;
}
for(int i=0;i<n;i++){
cin>>s[i];
if(s[i].size()>1){
flag[s[i][0]-'a']++;
}
reverse(s[i].begin(),s[i].end());
for(int j=0;j<s[i].size();j++){
p[s[i][j]-'a'].len[j]++;
}
}
for(int i=0;i<26;i++){
for(int j=0;j<maxn-1;j++){
if(p[i].len[j]>=26){
int d = p[i].len[j]/26;
p[i].len[j]%=26;
p[i].len[j+1]+=d;
}
if(p[i].len[j]>0){
p[i].L=max(p[i].L,j);
}
}
}
sort(p,p+26,cmp);
for(int i=0;i<26;i++){
p[i].v=i;
}
for(int i=0;i<26;i++){
if(flag[p[i].w]&&p[i].v==0){
swap(p[i].v,p[i+1].v);
}else break;
}
long long ans = 0;
long long value[26];
for(int i=0;i<26;i++){
value[p[i].w]=p[i].v;
}
for(int i=0;i<n;i++){
long long now = 1;
for(int j=0;j<s[i].size();j++){
ans=(ans+(value[s[i][j]-'a']*now)%mod)%mod;
now=(now*26)%mod;
}
}
cout<<"Case #"<<cas<<": "<<ans<<endl;
}
}

hdu 6034 B - Balala Power! 贪心的更多相关文章

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

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

  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. HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1

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

  5. HDU 6034 17多校1 Balala Power!(思维 排序)

    Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...

  6. hdu 6034 Balala Power!

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

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

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

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

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

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

随机推荐

  1. 使用 curses 函数库管理基于文本的屏幕

    curses 函数库提供了终端无关的方式来编写全屏幕的基于字符的程序.curses 还可以管理键盘,提供了一种简单易用的非阻塞字符输入模式. curses 函数库能够优化光标的移动并最小化需要对屏幕进 ...

  2. 卸载impala

    1):删除impala rm -rf $(find / -name "*impala*") 2):卸载impala相关依赖 rm -rf $(find / -name " ...

  3. 带你了解zabbix如何监控mysql主从到报警触发

    本章博客我们一起来聊一聊如何监控mysql数据库主从状态? 思路梳理: 1)首先我们都知道,判断Mysql主从是否正常,是通过主从上面的SQL和IO线程都为yes状态判断(通过awk取值,grep过滤 ...

  4. python 链接数据库错误

    用python3链接oracle产生错误: DPI-1047: Cannot locate a 64-bit Oracle Client library: "The specified mo ...

  5. tomcat配置调优与安全总结

    http://vekergu.blog.51cto.com/9966832/1672931 tomcat配置调优与安全总结 作为运维,避免不了与tomcat打交道,然而作者发现网络上关于tomcat配 ...

  6. sentinel-dashboard安装、运行(ubuntu)

    下载页面https://github.com/alibaba/Sentinel/releases wget -P /opt/downloads https://github.com/alibaba/S ...

  7. JavaSE| 面向对象的三大特征

    1.面向对象的基本特征之一:封装Encapsulation 目的:隐藏实现细节,让使用者方便,让代码更安全 将对象的属性和行为封装起来,其载体就是类.类通常对客户隐藏其实现细节,这就是封装的思想. 封 ...

  8. jsp的c标签使用

    http://blog.csdn.net/chabale/article/details/9406437

  9. NSL:CPK_NN神经网络实现预测哪个样本与哪个样本处在同一层,从而科学规避我国煤矿突水灾难—Jason niu

    load water_data.mat attributes = mapminmax(attributes); P_train = attributes(:,1:35); T_train = clas ...

  10. NP:建立可视化输入的二次函数数据点集np.linspace+np.random.shuffle+np.random.normal

    import numpy as np import matplotlib.pyplot as plt def fix_seed(seed=1): #重复观看一样东西 # reproducible np ...