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− ...
随机推荐
- 5月13 PDO数据访问抽象层
方法1:较简单的 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- ActiveMQ producer 提交事务时突然宕机,会发生什么
producer 在提交事务时,发生宕机,commit 的命令没有发送到 broker,这时会发生什么? ActiveMQ 开启事务发送消息的步骤: session.getTransactionCon ...
- 操作系统IIS安装
IIS在不同的操作系统的安装稍有些差异,如: 1.Windows XP 快捷安装IIS的话,推荐使用IIS一键安装程序包.或者找响应文件包i386,安装所需文件 2.Windows 7 安装IIS,则 ...
- Ubuntu 14.04下如何更换更新源(更新为163源)
之前的安装ubuntu桌面版的之后安装yum,vim等会遇到一些问题, 比如:Ubuntu 14.04下如何更换更新源(更新为163源) 解决: http://jingyan.baidu.com/ar ...
- laravel上传文件FTP驱动配置
FTP驱动配置 Laravel 的文件系统集成了 FTP 操作,不过,框架默认的配置文件 filesystems.php 并没有提供示例配置.如果你需要配置一个FTP文件系统,可以使用以下示例配置: ...
- learning at command AT+CGSN
AT command AT+CGSN [Purpose] Learning how to get mobile module international Mobile Equipment ...
- learning scala ide tools install
reference : https://www.jetbrains.com/help/idea/install-and-set-up-product.html env in ubuntu 16.04 ...
- WPF 创建自定义控件及自定义事件
1 创建自定义控件及自定义事件 /// <summary> /// 演示用的自定义控件 /// </summary> public class ExtButton : Butt ...
- day8-python函数
函数的简介 函数就是完成特定功能的一个语句组,这组语句可以作为一个单位使用,并且给它取一个名字. 降低编程难度 代码重用 可以通过函数名在程序的不同地方多长执行,这通常叫函数调用(.). 预定义函数 ...
- Saiku的基本使用介绍(三)
Saiku的基本使用介绍(这里都是使用Admin用户登录系统) 1.启动安装好的Saiku ( ./start-saiku.sh ) ,浏览器使用访问系统 http://localhost:8080 ...