2017 多校训练 1002 Balala Power!
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3757 Accepted Submission(s): 907

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)
a
2
aa
bb
3
a
ba
abc
Case #2: 1323
Case #3: 18221
/*
* @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!的更多相关文章
- 「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 ...
- 【2017多校训练08 1002】【HDOJ 6134】Battlestation Operational
典型的数列反演题. 运用莫比乌斯反演的一个结论 $[n = 1] = \sum_{d | n} \mu(d)$,将表达式做如下转化: $$ ans = \sum_{i=1}^n \sum_{j=1}^ ...
- 2017 多校训练 1006 Function
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 「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 ...
- 「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 ...
- 「2017 Multi-University Training Contest 8」2017多校训练8
1009 I am your Father! (最小树形图-朱刘算法) 题目链接 HDU6141 I am your Father! 求有向图最大生成树,要求n的父节点尽量小. 我们将所有wi变为-w ...
- 【双向bfs】2017多校训练十 HDU 6171 Admiral
[题意] 现在给出一个三角矩阵,如果0编号的在点(x,y)的话,可以和(x+1,y),(x-1,y),(x+1,y+1),(x-1,y-1)这些点进行交换. 我们每一次只能对0点和其他点进行交换.问最 ...
- 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge
acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线 ...
- 【(好题)组合数+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 ...
随机推荐
- 增大hadoop client内存
export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS" 问题场景:sqoop import时报OOM
- uva1267 Network
https://vjudge.net/problem/UVA-1267 题意: 有一棵树,上面有一个放着水源的点s,给出一个数k,这个水源可以覆盖路径长度到s不超过k的叶子节点.现在需要把所有的叶子节 ...
- 化繁为简 经典的汉诺塔递归问题 in Java
问题描述 在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度教的主神梵天在创造世界的时候,在其中一根针上从下到上地穿好了由大到小的64片金片,这就是所谓的汉诺塔.不论白天黑 ...
- UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作
AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...
- Drying poj3104(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7916 Accepted: 2006 Descriptio ...
- 通过修改 LayoutInflater,全局替换字体!!!
序 在 Android 下使用自定义字体已经是一个比较常见的需求了,最近也做了个比较深入的研究. 那么按照惯例我又要出个一篇有关 Android 修改字体相关的文章,但是写下来发现内容还挺多的,所以我 ...
- JAVAWEB复习资料-01
CSS中@import和link两种插入样式表方式有什么不同? 1.link属于HTML标签,除了引入css文件之外还能定义RSS等,而@import只能用于加载CSS. 2.link在引用CSS时, ...
- Hadoop就是一个别人造好的轮子
这个想法源自于我看了<Hadoop: The Definitive Guide>的Part I Ch 2中MapReduce的引入和介绍,书中先说了怎么通过原始的办法处理数据,然后引入到如 ...
- bootstrap 轮播模板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Levenshtein Distance + LCS 算法计算两个字符串的相似度
//LD最短编辑路径算法 public static int LevenshteinDistance(string source, string target) { int cell = source ...