HDU 6034 17多校1 Balala Power!(思维 排序)
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.
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)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std; const int MOD=1e9+;
const int maxn=1e5+;
struct word
{
int pos;//表示第几个字母
int time[maxn];//各个字母在各位置出现的次数
}q[];
//不加&的话会TLE,用&比不用快
bool cmp(word &a,word &b)//从小到大排序
{
for(int i=maxn-;i>;i--)
{
if(a.time[i]!=b.time[i])
return a.time[i]<b.time[i];
}
return a.time[]<b.time[];
} int main()
{
int n,len;
char s[maxn];
int t=;
while(~scanf("%d",&n))
{
int flag[]={};
//用来标记各个字母是否可以对应0,从0开始
//0表示可以,1表示不可以
for(int i=;i<;i++)
{
q[i].pos=i;
for(int j=;j<maxn;j++)
q[i].time[j]=;
}
while(n--)
{
scanf("%s",&s);
len=strlen(s);
if(len>)flag[s[]-'a']=;
//不能对应0
for(int i=;i<len;i++)
{
int y=len-i;//位置反着记
q[s[i]-'a'].time[y]++;
//开始做进位处理
while(q[s[i]-'a'].time[y]==)
{
q[s[i]-'a'].time[y]=;
y++;
q[s[i]-'a'].time[y]++;
}
}
}
sort(q,q+,cmp);//把26个字母按从小到大的赋值排好序
//开始处理前导0
int op;//op即赋前导0的位置
for(int i=;i<;i++)
{
if(flag[q[i].pos]==)
{
op=i;
break;
}
}
long long sum=,sumi=,num,m=;
for(int i=;i<;i++)
{
sumi=;
if(i==op)
num=;
else
{
num=m;
m++;
}
for(int j=maxn-;j>;j--)
{
sumi=(sumi*)%MOD;
sumi=(sumi+(long long)q[i].time[j]*num)%MOD;
}
sum=(sum+sumi)%MOD;
}
printf("Case #%d: %lld\n",t++,sum);
}
return ;
}
HDU 6034 17多校1 Balala Power!(思维 排序)的更多相关文章
- HDU 3130 17多校7 Kolakoski(思维简单)
Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...
- HDU 6098 17多校6 Inversion(思维+优化)
Problem Description Give an array A, the index starts from 1.Now we want to know Bi=maxi∤jAj , i≥2. ...
- HDU 6034 Balala Power!【排序/进制思维】
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java ...
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
- HDU 6038 17多校1 Function(找循环节/环)
Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...
- HDU 6103 17多校6 Kirinriki(双指针维护)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑i=0n− ...
随机推荐
- 【其他】【PL/SQL Developer】【1】解决PL/SQL Developer过期的情况
正文: 1,开始菜单,搜索regedit,回车打开(即日常搜索电脑安装的软件的地方,regedit就是注册表) 2,按HKEY_CURRENT_USER\Software\Allround Autom ...
- 四则运算web最终版
经过若干时间的奋战,终于完成了web版四则运算程序.团队成员:井小普.张贺. 设计思想: 在之前的程序基础上两人结合开发web系统. 首先,进行登录注册界面的编写,不同用户,对应不同的错题库,答题记录 ...
- 导出csv文件数字会自动变科学计数法的解决方法
其实这个问题跟用什么语言导出csv文件没有关系.Excel显示数字时,如果数字大于12位,它会自动转化为科学计数法:如果数字大于15位,它不仅用于科学技术费表示,还会只保留高15位,其他位都变0.解决 ...
- php 文件压缩
1.php文件压缩代码: $zip = new ZipArchive;if($zip->open('aaa.zip',ZipArchive::OVERWRITE)===TRUE){ //aaa. ...
- 2017-4-28/PHP实现Redis
谈一谈Redis的数据结构,如果换做PHP,怎么实现?如果再考虑用上LFU或LRU,又该如何实现? Redis的数据结构有String.List.Set.Sorted Set.Hash等,而PHP ...
- Hadoop---18/06/03 20:15:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable starting yarn daemons
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin- ...
- Win10怎么设置打开文件的默认程序
- 适应c++ 新特性 - 与我 - 多年传统方式开发(新特性参考微软标准:https://msdn.microsoft.com/zh-cn/library/hh279654.aspx)
公司同事都在积极使用c++的新特性,并对其赞不绝口,而自己一直做着传统的c++开发方式,到底这些新特性如何,又是怎么提高开发效率的,我依然在疑问当中,从同事的说法和实际代码操练里,确实在减少代码量,集 ...
- spring boot 打包可以运行,但是执行main方法不能运行
报错信息如下 2017-10-23 15:16:09.750 ERROR 7664 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReport ...
- nodejs项目文件搭建环境
nodeJS,作为一门较为“新鲜的”的原因,近年来普遍受到一些前端想转为全栈的ITer青睐,在想用nodeJS配合数据库开发出一个小玩意的路上,萌新们第一步便要遇到就是环境的支持.node作为Java ...