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− ...
随机推荐
- 把xml转成javabean的工具类
import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import javax.x ...
- String.Format 格式化例子
//格式为sring输出// Label1.Text = string.Format("asdfadsf{0}adsfasdf",a);替换符// Label2.Text ...
- Homebrew 安装mysql
在mac上安装软件,无疑安装一个brew是个很好的选择,关于brew是什么,怎么安装建议去brew官网查看, 附上地址:brew官网 还有一篇博文 http://www.cnblogs.com/xd ...
- Git:合并分支冲突问题
首先创建分支feature1,并且修改readme.txt内容,再在该分支上提交. 切换回master分支, 并且修改readme.txt内容,再在master分支上提交. 此时的分支路线如下,合并时 ...
- Android Studio向项目添加C/C++原生代码教程
说明:本文相当于官方文档的个人重新实现,官方文档链接:https://developer.android.com/studio/projects/add-native-code 向项目添加C/C++代 ...
- Linux确认网口对应配置文件
服务器经常是多网卡多网口,我们在某个网口插上网线后,到/etc/sysconfig/network-scripts/下配置ip时需要确定插上网线的网口对应的是哪个配置文件(比如是eth0还是eth1) ...
- MySql查询最近一个月,一周,一天
最近一个月 SELECT * FROM table WHERE DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(time); 本月.当前月 SELEC ...
- ubuntu 挂载虚拟机vdi文件
sudo apt-get install nbd-server nbd-client qemu-kvm # rmmod nbd # modprobe nbd max_part=8 # qemu- ...
- Weka里如何将arff文件或csv文件批量导入MySQL数据库(六)
这里不多说,直接上干货! 前提博客是 Weka中数据挖掘与机器学习系列之数据格式ARFF和CSV文件格式之间的转换(四) 1.将arff文件批量导入MySQL数据库 我在这里,arff文件以Weka安 ...
- linux 安装 DenyHosts 防止密码被暴力破解
DenyHosts DenyHosts是Python语言写的一个程序,它会分析sshd的日志文件(/var/log/secure),当发现重 复的攻击时就会记录IP到/etc/hosts.deny文件 ...