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− ...
随机推荐
- SecureCRT自动记录日志
From: http://lzj0470.iteye.com/blog/1189368 今天在推特上看到有人谈起SecureCRT日志记录的问题,貌似很多人都有这习惯 我是开始工作后才使用Secure ...
- Async:简洁优雅的异步之道
前言 在异步处理方案中,目前最为简洁优雅的便是 async函数(以下简称A函数).经过必要的分块包装后,A函数能使多个相关的异步操作如同同步操作一样聚合起来,使其相互间的关系更为清晰.过程更为简洁.调 ...
- 《高性能SQL调优精要与案例解析》一书谈主流关系库SQL调优(SQL TUNING或SQL优化)核心机制之——索引(index)
继<高性能SQL调优精要与案例解析>一书谈SQL调优(SQL TUNING或SQL优化),我们今天就谈谈各主流关系库中,占据SQL调优技术和工作半壁江山的.最重要的核心机制之一——索引(i ...
- JDK8的ConcurrentHashMap也会造成CPU 100%
转载:不止 JDK7 的 HashMap ,JDK8 的 ConcurrentHashMap 也会造成 CPU 100%?原因与解决~ 现象 大家可能都听过JDK7中的HashMap在多线程环境下可能 ...
- linux文件软链接、硬链接
在linux ext2文件系统中,一个文件的属性存放在inode中,而数据存放在block中.每个文件占用一个inode,inode中记录了文件的权限和block地址,通过inode可以定位到bloc ...
- CentOS安装教程(VMware)
1.下载镜像文件 下载链接:https://wiki.centos.org/Download LinveCD--可装在CD光盘上启动的版本. LiveDVD--可装在DVD光盘上启动的版本. DVD1 ...
- summary_16th Nov, 2018
一. 编程语言的分类: a. 机器语言:直接使用二进制指令去编写程序,必须考虑硬件细节 b:汇编语言:用英文标签取代二进制指令去编写程序,必须考虑硬件细节 c:高级语言:用人类能理解的方式编写程序,通 ...
- axios API速查表
原来jq自带ajax方法,但是近期项目用vue,在vue项目中发送ajax请求原来用vue resource,现在更推荐使用axios,因为axios和vue更配! GET 请求 // Make a ...
- 我眼中的Linux系统和红帽RHCE认证
牛顿曾经说过“我不知道在别人看来,我是什么样的人:但在我自己看来,我不过就象是一个在海滨玩耍的小孩,为不时发现比寻常更为光滑的一块卵石或比寻常更为美丽的一片贝壳而沾沾自喜,而对于展现在我面前的浩瀚的真 ...
- day30 操作系统介绍 进程的创建
今日内容 一.操作系统的简单介绍 二,并发与并行 三.同步异步阻塞非阻塞 四.multiprocess模块 1. 操作系统的简单介绍 多道技术(重点) 空间复用: 时间复用: 进程之间是空间隔离的 分 ...