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. (2017多校训练第一场)HDU - 6034 Balala Power! 贪心

    很容易就想到把每个字母的权重都算出来,然后把权重最大的赋值成25,次大的赋值成24......以此类推. 但是字符串长度最大为100000,也就是说一个字母的权重最大是26^100000次方左右,太大 ...

  2. Balala Power(贪心)

    hduoj好像挂了,就不给链接了哇... 题意:给n个字符串,然后每个字母可以转化为其他的25个小写字母,字母a-z依次表示0-25,其中不同的两字母不能转化为相同的字母,让求转化后的字符串的总和最大 ...

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

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

  4. HDU 2017 多校联赛 1002 Balala Power!

    题目描述 Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge the ...

  5. HDU 2795 Billboard (线段树+贪心)

    HDU 2795 Billboard (线段树+贪心) 手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/articl ...

  6. HDU6034 Balala Power!

    Balala Power! 这道题的题意就是给你n个字符串,让你对每个字符赋值(0~25)(注意,每种字符只能赋一个值),然后让你求这些字符的26进制的和的最大值,并且用十进制输出这个最大值. 解释一 ...

  7. HDU 6034 Balala Power!

    题目内容 题意:就是给a~z之间的每个字母1个0~25之间的数,即为每个字母的权重(权重的分配依据于每个字母所做的贡献),相当于26进制数.求使所有字符串之和最大的值是多少? 贪心,将所有字母按照所做 ...

  8. HDU 5281 Senior's Gun (贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...

  9. hdu 6203 ping ping ping(贪心+树状数组+dfs序)

    题目链接:hdu 6203 ping ping ping 题意: 给你一棵n+1个节点树,现在有q条路径不通,问你最少有多少个节点坏掉了. 题解: 考虑贪心,对这q条路径求一下lca,按照lca的深度 ...

最新文章

  1. 【学习笔记】超简单的多项式快速幂
  2. 了解ReactOS调试
  3. 03_Android项目中读写文本文件的代码
  4. 集算报表用Java动态修改报表数据源
  5. 解决 dockerfile 构建镜像报错: [WARNING]: Empty continuation lines will become errors in a future release.
  6. WeMos-D1R2的使用
  7. csv python 只写一次_在Python CSV Writer循环中写入一次头
  8. EPOLL AND Nonblocking I/O
  9. mysql my.cnf中忽略大小写_修改my.cnf ,使mysql 的表面不区分大小写
  10. jquery 同胞 siblings next nextAll nextUtil pre preAll preUtil
  11. [网安实践II] 实验2. 密码学实验
  12. Android空调遥控器代码,空调代码—万能遥控器要如何正确设置空调代码?
  13. 计算机一直显示配置更新失败怎么办,电脑更新新系统的时候出现配置更新失败问题怎么办...
  14. html文档头部标记,HTML头部标记
  15. [Xilinx FPGA] #4 Xilinx FPGA 芯片命名规则与查询方法
  16. [HCIP]MPLS解决路由黑洞
  17. mysql8.017安装教程_mysql 8.0.17 安装图文教程
  18. Orcale 批量更新sql
  19. MyBatis框架(IDEA-Maven篇)---从小白到入门
  20. 路由器5G WiFi不工作维修分析

热门文章

  1. Oracle-临时表空间(组)解读
  2. Linux内核链表之共享双链表
  3. java程序运行堆栈分析
  4. thymeleaf+layui加载页面渲染时,TemplateProcessingException: Could not parse as expression:
  5. KMM+Compose 开发一个Kotlin多平台应用
  6. ViewModel优雅的弹加载窗和获取Context
  7. 更新至Android Studio4.1后发现as打不开的解决方案
  8. 基础理论:啥是分布函数CDF、啥叫联合分布?
  9. python课堂笔记手抄图片_超简单又漂亮的手抄报图片
  10. python3 ftplib_ftplib — FTP protocol client