Balala Power!

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3757    Accepted Submission(s): 907

Problem Description

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.

 
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
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6044 6043 6042 6041 6040 
/*
* @Author: Lyucheng
* @Date: 2017-07-26 11:03:09
* @Last Modified by: Lyucheng
* @Last Modified time: 2017-07-26 17:24:29
*/
/*
题意:给你n个字符串,只包含a~z的字符,你可以给字符赋值0~25,但是不同的字符的值不能相同,要求得到n个字符串的和最大 思路:相当于n个26进制的数,然后考虑每个字符在每个字符串中位置对结果的贡献,贡献最多的为25,其次是24,以此类推,要
注意的问题就是前导零的问题
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> #define LL long long
#define MAXN 100005
#define MAXK 26
const LL MOD=1e9+;
using namespace std; struct Node{
int pos;//标记字符
int num[MAXN];
bool operator < (const Node & other) const {//重载小于号按照优先级排序
for(int i=MAXN-;i>;i--){
if(num[i]!=other.num[i])
return num[i]<other.num[i];
}
return num[]<other.num[];
}
}node[MAXK+];
int n;
char str[MAXN];
bool vis[MAXK];//标记是否不能为第一个字符
int len;
int ca=; inline void init(){
for(int i=;i<MAXK;i++){
node[i].pos=i;
for(int j=;j<MAXN;j++){
node[i].num[j]=;
}
}
memset(vis,false,sizeof vis);
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<n;i++){
scanf("%s",str);
len=strlen(str);
if(len>){//如果不是单个字符那么,第一个字符就不能为零
vis[str[]-'a']=true;
}
for(int j=;j<len;j++){
int x=str[j]-'a';//字符
int y=len-j-;//位置
node[x].num[y]++;
while(node[x].num[y]==MAXK){//满了26个了,不管是几都要进位
node[x].num[y++]=;
node[x].num[y]++;
}
}
}
sort(node,node+MAXK);
//找第一个能为零的字符
int pos=-;
for(int i=;i<MAXK;i++){//从优先级最小的开始找
if(vis[node[i].pos]==false){
pos=i;
break;
}
} int POW=;
LL res=;
for(int i=;i<MAXK;i++){
if(i==pos){
POW=;
}else if(i<pos){
POW=i+;
}else{
POW=i;
}
LL cur=;
for(int j=MAXN-;j>=;j--){
cur = (cur * MAXK) % MOD;
cur = (cur + (LL)node[i].num[j] * POW) % MOD;
}
res = (res + cur)%MOD;
}
printf("Case #%d: %lld\n",ca++,res);
}
return ;
}

2017 多校训练 1002 Balala Power!的更多相关文章

  1. 「2017 Multi-University Training Contest 1」2017多校训练1

    1001 Add More Zero(签到题) 题目链接 HDU6033 Add More Zero 找出最大的k,使得\(2^m-1\ge 10^k\). 直接取log,-1可以忽略不计. #inc ...

  2. 【2017多校训练08 1002】【HDOJ 6134】Battlestation Operational

    典型的数列反演题. 运用莫比乌斯反演的一个结论 $[n = 1] = \sum_{d | n} \mu(d)$,将表达式做如下转化: $$ ans = \sum_{i=1}^n \sum_{j=1}^ ...

  3. 2017 多校训练 1006 Function

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

  4. 「2017 Multi-University Training Contest 7」2017多校训练7

    1002 Build a tree(递归) 题目链接 HDU6121 Build a tree 有一棵n个点的有根树,标号为0到n-1,i号点的父亲是\(\lfloor\frac{i-1}{k}\rf ...

  5. 「2017 Multi-University Training Contest 2」2017多校训练2

    1001 Is Derek lying 题目链接 HDU6045 Is Derek lying? 给出两个人选择题的回答,问得分分别为x和y是否可能.(\(1\le N \le 80000,0\le ...

  6. 「2017 Multi-University Training Contest 8」2017多校训练8

    1009 I am your Father! (最小树形图-朱刘算法) 题目链接 HDU6141 I am your Father! 求有向图最大生成树,要求n的父节点尽量小. 我们将所有wi变为-w ...

  7. 【双向bfs】2017多校训练十 HDU 6171 Admiral

    [题意] 现在给出一个三角矩阵,如果0编号的在点(x,y)的话,可以和(x+1,y),(x-1,y),(x+1,y+1),(x-1,y-1)这些点进行交换. 我们每一次只能对0点和其他点进行交换.问最 ...

  8. 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge

    acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线 ...

  9. 【(好题)组合数+Lucas定理+公式递推(lowbit+滚动数组)+打表找规律】2017多校训练七 HDU 6129 Just do it

    http://acm.hdu.edu.cn/showproblem.php?pid=6129 [题意] 对于一个长度为n的序列a,我们可以计算b[i]=a1^a2^......^ai,这样得到序列b ...

随机推荐

  1. [js高手之路] html5 canvas系列教程 - 认识canvas以及基本使用方法

    canvas是html5中引入的一个新元素,俗称画布,既然是画布,当然是用来画图的.canvas技术指的是利用javascript操作canvas元素绘制图形的技术,要使用canvas,一定要浏览器支 ...

  2. 51nod 1126 求递推序列的第N项 思路:递推模拟,求循环节。详细注释

    题目: 看起来比较难,范围10^9 O(n)都过不了,但是仅仅是看起来.(虽然我WA了7次 TLE了3次,被自己蠢哭) 我们观察到 0 <= f[i] <= 6 就简单了,就像小学初中学的 ...

  3. ARCGIS切图:TPK文件的空间参考为地理坐标系

    先来吐槽一下,之前习惯了百度地图API,所以一直习惯直接将经纬度点添加到地图上进行显示,目前使用ARCGIS RUNTIME FOR ANDROID进行开发,在地图上加点需要原始点的坐标为投影坐标系, ...

  4. handlebar JS模板使用笔记

    直接上代码: (定义模板) (编译注入) ***知识点*** //数据必须为Json数据(强调:jsonp数据不行,和json是两种数据,jsonp多了callback回调函数来包裹json数据) 遍 ...

  5. sql的存储过程使用详解--基本语法

    存储过程简介 SQL语句需要先编译然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给定参数(如果该存储 ...

  6. Mysq基础

    本文是之前看博客时候的记录,忘记是哪位仁兄的了,在这只做一次转载: 常见误区 count(1)和count(primary_key) 优于 count(*) 很多人为了统计记录条数,就使用 count ...

  7. 【转】Windows自动连接、断开无线网络

    前提是先连接到指定的WiFi网络上. 然后通过 netsh wlan export profile 将网络配置文件导出,然后使用如下命令添加配置文件到指定的网络接口上,再执行连接命令即可. netsh ...

  8. ssm搭建报错

    在搭建ssm框架时候踩得坑:1.对于拦截器url-parttern的设置:第一次设置的是/** 本以为这个是表示拦截所有,没想到这是错误的写法,正确的写法是/    启动项目不会报错,但是会出现404 ...

  9. C#仪器数据文件解析-Excel文件(xls、xlsx)

    不少仪器工作站可以将数据导出为Excel文件,包括97-2003版本的xls文件和2007+的xlsx文件. 采集Excel文件相比采集pdf文件更容易.程序更健壮,毕竟Excel中数据有明确的行.列 ...

  10. 提纲挈领webrtc之NS(noise suppression)模块

    Noise suppression,就是大家说的降噪.这种降噪是把人声和非人声区分开来,把非人声当成噪声. 一段包含人声和噪声的音频经过该模块处理,从理论上讲,只剩下人声了. webrtc的NS在业内 ...