hdu 6034 B - Balala Power! 贪心
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! 贪心的更多相关文章
- HDU 6034 Balala Power! (贪心+坑题)
题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...
- 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 ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...
- HDU 6034 17多校1 Balala Power!(思维 排序)
Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...
- hdu 6034 Balala Power!
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- HDU 6034 Balala Power!【排序/进制思维】
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java ...
- 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 ...
随机推荐
- 一脸懵逼学习KafKa集群的安装搭建--(一种高吞吐量的分布式发布订阅消息系统)
kafka的前言知识: :Kafka是什么? 在流式计算中,Kafka一般用来缓存数据,Storm通过消费Kafka的数据进行计算.kafka是一个生产-消费模型. Producer:生产者,只负责数 ...
- lojround3
A.绯色 IOI(开端) 首先注意到是完全图,数据范围又很大,肯定要观察一些性质 我们化简一下式子 发现其实是要求simga(xixj)最大 那么结论就很好想了 最大的和次大的第三大的连一起...然后 ...
- OAuth2:隐式授权(Implicit Grant)类型的开放授权
适用范围 仅需临时访问的场景 用户会定期在API提供者那里进行登录 OAuth客户端运行在浏览器中(Javascript.Flash等) 浏览器绝对可信,因为该类型可能会将访问令牌泄露给恶意用户或应用 ...
- MVC5干货篇,目录和路由
MVC目录结构概述 文件夹或文件 描述 备注 /App_Data 此文件夹用于存放私有数据,如XML,或者SQL Server Express\SQLite的数据库文件,或其他基于文件的存储库 IIS ...
- scrapy笔记
1.关于请求url状态码重定向问题: from scrapy import Request handle_httpstatus_list = [404, 403, 500, 503, 521, 522 ...
- LAMP编译安装部分
# yum install -y apr-devel apr-util-devel pcre-devel # wget http://mirror.bit.edu.cn/apache/httpd/ht ...
- 分布式配置hadoop2.5.0 2.6.x
1. sudo vim /etc/hostname 在master的机器上,改成 master 在slave上写 slave01,02,03...... 配置好后重启. 2. sudo vi ...
- html5的audio实现高仿微信语音播放效果(实际项目)
HTML部分: <div class="tab-pane fade dialog-record" id="dialogRecord"> <vo ...
- 最短路径(给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。 说明:每次只能向下或者向右移动一步。)
给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小. 说明:每次只能向下或者向右移动一步. 例: 输入: [ [1,3,1], [1,5,1], [ ...
- day30 网络编程 之进程,线程,协程
进程点进去 线程点进去 协程点进去 什么是进程 进程(有时称为重量级进程)是一个执行中的程序.每个进程都拥有自己的地址空间.内存.数据栈以及其他用于跟踪执行的辅助数据.同一个程序执行两次,属于是两个不 ...