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 ...
随机推荐
- XML使用与总结
xml是一种比较方便的数据储存方式,它适用于小数据的存储.最常见的适用地方莫过于各种web.config与app.config了. 一.创建一个简单的xml路径 public static str ...
- x86 版的 Arduino Intel Galileo 开发板的体验、分析和应用
1.前言 在今年(2013)罗马举办的首届欧洲 Make Faire 上,Intel 向对外发布了采用 x86 构架的 Arduino 开发板:Intel Galileo.这无疑是一个开源硬件领域的重 ...
- WPF中datagrid不显示滚动条问题
WPF中DataGrid是自带滚动条的,当内容显示不下时可以使用滚动条显示.但是,开发中遇到了DataGrid一直不显示滚动条.之前也曾遇到过同类问题,再次经过查找,发现是StackPanel的原因, ...
- WPF: Hide grid row
http://stackoverflow.com/questions/2502178/wpf-hide-grid-row Setting all the Items in the Row to Vis ...
- kudu的读取数据流程
当客户端从Kudu的表中读取数据时,必须首先建立需要连接的系列tablet服务器. 通过执行tablet发现过程(如上所述)来确定包含要读取的主关键字范围的tablet的位置(读取不必在领导者tabl ...
- 聊聊Docker数据卷和数据卷容器
当程序在容器运行的时候,特别是需要与其他容器中的程序或容器外部程序进行沟通交流,这时需要进行数据交换,作为常用的两种沟通数据的方式,网络通信与文件读写是需要提供给程序的支持, [数据卷] 文件是数据持 ...
- Python交互图表可视化Bokeh:6. 轴线| 浮动| 多图表
绘图表达进阶操作 ① 轴线设置② 浮动设置③ 多图表设置 1. 轴线标签设置 设置字符串 import numpy as np import pandas as pd import matplotli ...
- TMS320DM642学习----第一篇(硬件连接)
DSP设备型号:SEED-DTK-VPM642(目前实验室用途:视频处理,图像处理方向,预计搭载目标跟踪以及云台防抖等算法) 官网链接:http://www.seeddsp.com/index.php ...
- win 10 slmgr.vbs -xpr 无法运行,被豆麦笔记打开解决方法
win 10 slmgr.vbs -xpr 无法运行,被豆麦笔记打开解决方法 删除这个豆麦笔记 如果之前已经在 控制面板 程序中卸载过,那么是找不到的,我们先运行 slmgr.vbs -xpr,这个时 ...
- JavaEE 之 log4j
1.log4j a.概念:一个非常优秀的开源日志记录工具 b.配置: ①src同目录下建立log4j.properties文件,书写: log4j.rootLogger=debug,appender1 ...