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 26hilariously.

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.

 
Input
The input contains multiple test cases.

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)

 
Output
For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
 
Sample Input
1
a
2
aa
bb
3
a
ba
abc
 
Sample Output
Case #1: 25
Case #2: 1323
Case #3: 18221
题意:将字符替换成一个数字,每个字符串各组成一个数(26进制),然后加起来和最大
解法:
1 很自然想到是25 24 23这样的替换顺序
2 考虑高精度带来的误差(包括进位和移位)
3 0放哪里,怎么处理简直坑到吐
4 倒序保存便于处理
 #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
const int mod = 1e9+;
const int maxn=1e5+;
struct Node{
int ans[maxn+];
int id;
bool operator < (const Node &a) const
{
for(int i = maxn-; i >= ; i--)
{
if(ans[i] > a.ans[i]) return ;
else if(ans[i] < a.ans[i]) return ;
else ;
}
}
}node[];
long long x[maxn];
void init(){
x[]=;
for(int i=;i<=maxn;i++){
x[i]=x[i-]*;
x[i]%=mod;
}
x[maxn]=;
}
bool Sort(Node a,Node b){
for(int i=;i<maxn;i++){
if(a.ans[i]<b.ans[i]){
return ;
}else if(a.ans[i]>b.ans[i]){
return ;
}
}
}
int flag[maxn];
int zero[maxn];
int cnt=;
int main(){
init();
int n;
while(~scanf("%d",&n)){
memset(flag,-,sizeof(flag));
memset(node,,sizeof(node));
memset(zero,,sizeof(zero));
char a[maxn];
for(int i=;i<n;i++){
scanf("%s",a);
int len=strlen(a);
if(len!=){
zero[a[]-'a']=;
}
for(int i=;i<len;i++){
node[a[i]-'a'].ans[len-i-]++;
}
}
// cout<<"A"<<endl;
for(int i=;i<;i++){
for(int j=;j<maxn;j++){
if(node[i].ans[j]>=){
node[i].ans[j+]+=node[i].ans[j]/;
node[i].ans[j]%=;
}
}
node[i].id=i;
}
//cout<<"B"<<endl;
sort(node,node+);
for(int i=;i<;i++){
flag[node[i].id]=-i-;
} for(int i=;i<;i++){
if(zero[node[i].id]&&flag[node[i].id]==){
for(int j=;j>=;j--){
if(zero[node[j].id]==){
for(int k=;k>=j+;k--){
flag[node[k].id]=flag[node[k-].id];
}
flag[node[j].id]=;
break;
}
}
break;
}
}
long long ans=;
for(int i=;i<;i++){
for(int j=;j<maxn;j++){
ans+=(x[j]*node[i].ans[j]*flag[node[i].id]%mod)%mod;
}
}
printf("Case #%d: %lld\n",cnt++,ans%mod);
}
return ;
}

2017 Multi-University Training Contest - Team 1 Balala Power!的更多相关文章

  1. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  2. 2017 Multi-University Training Contest - Team 1 1002&&hdu 6034

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  5. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  6. 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】

    Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  7. 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】

    Big binary tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

随机推荐

  1. [CPP - STL] swap技巧

    最近在看<Effective STL>,[条款17:使用“交换技巧”修整过剩容量]中提到容器的成函数void swap(container& from),即实现容器对象与from对 ...

  2. jenkins页面不刷新,设置tomcat缓存

    装jenkins的时候,部署后,访问jenkins页面,输入管理员密码后,出现jenkins页面停滞,看后台catlina日志,发现需要增加tomcat容器的cache,才能加载一些jar包,下面是设 ...

  3. SSL handshake_decode_error

    查看布署在Amazon服务器上的日志时,发现如下错误: generated SERVER ALERT: Fatal - Handshake Failure - handshake_decode_err ...

  4. excel 基本用法

  5. ubuntu bcompare 安装

    Terminal Install wget http://www.scootersoftware.com/bcompare-4.2.8.23479_amd64.deb sudo apt-get upd ...

  6. Linux中进程控制块PCB-------task_struct结构体结构

    Linux中task_struct用来控制管理进程,结构如下: struct task_struct { //说明了该进程是否可以执行,还是可中断等信息 volatile long state; // ...

  7. web缓存概述

    缓存无处不在,所展示出的仅仅是服务器端的缓存,我们从细节层面一层层分析 但是在此之前,我们先要知道什么是缓存与为什么要使用缓存,是时候百度一波喽~ 缓存就是数据交换的缓冲区(称作Cache),当某一硬 ...

  8. 安装ubuntu+Windows双系统, Windows启动项消失

    这里主要介绍grub分区损坏的问题: 首先介绍最简单的方法, 不确定能不能成功, 但是最好先用此方法, 毕竟最简单如果解决就不用下一个方法了. 1. (1)用U盘做一个ubuntu的镜像, 开机进入U ...

  9. CodeForces 1109E. Sasha and a Very Easy Test

    题目简述:给定$m \leq 10^9+9$,维护以下操作 1. "1 l r x":将序列$a[l], a[l+1], \dots, a[r]$都乘上$x$. 2. " ...

  10. css 属性相关

    css属性相关 宽和高 width属性可以为元素设置宽度, height属性可以为元素设置好高度 块级标签才能设置宽度,内联标签的宽度由内容来决定. 字体属性 文字字体 font-family 可以把 ...