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. 专用管理连接(DAC)和单用户模式

    数据库运维人员,在维护数据库时,有时会遇到一些特殊的情况,例如,SQL Server实例无法访问,此时需要用到管理员在紧急情况下专用的连接:有时,在做一些系统级别的配置修改时,当前数据库不能被其他用户 ...

  2. String StringBuffer StringBuilder 之间的区别

    StringBuffer与StringBuilder的区别: StringBuffer是jdk1.0版本出来的,线程安全,效率低 StringBuilder是jdk1.5版本出来的,线程不安全,效率高 ...

  3. crypto加密

    /* hash.js */     var crypto = require('crypto'); module.exports = function(){      this.encode = fu ...

  4. NavigationController的返回按钮自定义

    假设需求时这样: NavigationController下有2个视图,从A视图会Push到B视图,默认情况下,当显示视图B时,视图B的导航bar上会出现返回按钮,按钮标题文字默认为A视图的title ...

  5. 600集Python从入门到精通教程(懂中文就能学会)

    目录大纲: 本套教程15天 1-3   天内容为Linux基础命令 4-13  天内容为Python基础教程 14-15 天内容为 飞机大战项目演练 视频概括: 第一阶段(1-3天): 该阶段首先通过 ...

  6. YYHS-NOIP2017Training0928-ZCC loves Isaac

    题目描述 [背景]ZCC又在打Isaac.这次他打通了宝箱关进入了表箱关.[题目描述]表箱关有一个房间非常可怕,它由n个变异天启组成.每个天启都会在进入房间后吐出绿弹并炸向某一个位置且范围内只有一个天 ...

  7. centos7.2 linux 64位系统上安装mysql

    1.在线安装mysql 在终端中命令行下输入(在官网下载mysql): # wget https://dev.mysql.com/downloads/repo/yum/mysql57-communit ...

  8. Eclipse连接SQL Server 2008数据库 以及问题总结

    Eclipse中使用SQL server 2008数据库 一.准备材料 要能够使用数据库就要有相应的JDBC,所以我们要去Microsoft官网下载 https://www.microsoft.com ...

  9. Spring详解(七)------事务管理

    PS:本篇博客源码下载链接:http://pan.baidu.com/s/1mi3NhX2 密码:3io2 1.事务介绍 事务(Transaction),一般是指要做的或所做的事情.在计算机术语中是指 ...

  10. Mysql 协议嗅探

    需求 监听通过网卡的所有mysql流量,进行解析,可在不影响现有业务情况下,进行入侵检测(IDS)或数据集成 协议要点 起初发现 用mysql-front访问数据库和mysql 的客户端访问时数据包格 ...