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− ...
随机推荐
- javascript作用域、闭包、对象与原型链
原文作者总结得特别好,自己收藏一下.^-^ 1.作用域1.1函数作用域JS的在函数中定义的局部变量只对这个函数内部可见,称之谓函数作用域.它没有块级作用域(因此if.for等语句中的花括号不是独立作用 ...
- python-flask基本应用模板
1.模板继承 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- js向一个数组中插入元素的几个方法-性能比较
向一个数组中插入元素是平时很常见的一件事情.你可以使用push在数组尾部插入元素,可以用unshift在数组头部插入元素,也可以用splice在数组中间插入元素. 但是这些已知的方法,并不意味着没有更 ...
- flex布局文本过长不显示省略号
https://www.cnblogs.com/tgxh/p/6916930.html 解决方法: 给flex子元素添加css: white-space: nowrap; text-overflow: ...
- .NET面试问题二
1.MVC中如何保持Session? 可以使用tempdata,viewdata,viewbag三种方式 tempdata:不同的控制器类或者动作间转换时保持数据,页面转向时也保持数据,是一个内部的S ...
- 判断window.open的页面是否已经被关
<!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鸟教程 ...
- python-flask基础
get请求: 使用场景:如果只对服务器获取数据,并没有对服务器产生任何影响,那么这时候使用get请求. 传参:get请求传参是放在url中,并且是通过’?’的形式来指定key和value的. post ...
- Java Web(三) Servlet会话管理
会话跟踪 什么是会话? 可简单理解为,用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭服务器,整个过程称为一个会话.从特定客户端到服务器的一系列请求称为会话.记录会话信息的技术称 ...
- Intellij下Jquery中文乱码
今天在用Jquery+Ajax实现检查用户名是否可用的功能时,意外的发生了乱码,谷歌了很久后终于找到了解决办法: 把js文件复制一份在桌面 用记事本打开,另存为UTF-8格式 复制粘贴回去,覆盖之前的 ...
- 模块化&os&sys
syspath python 使用import模块调用的优先级是根据sys.path路径来的,此变量中位置在列表中的先后顺序来调用,如果先找到对应的模块,则先调用此模块. import sys pri ...