2017 Multi-University Training Contest - Team 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 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.
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 <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!的更多相关文章
- 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 ...
- 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 ...
- 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) ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 动态inventory脚本的python实现
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' 基于python的动态inventory脚本实例 ''' import os import sys ...
- hdu-5000 Clone(dp)
题目链接: Clone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- 基于aspectj实现AOP操作的两种方式——注解方式
- C/C++获取Linux系统CPU和内存及硬盘使用情况
需求分析: 不使用Top df free 等命令,利用C/C++获取Linux系统CPU和内存及硬盘使用情况 实现: //通过获取/proc/stat (CPU)和/proc/meminfo(内存 ...
- Sherlock and the Encrypted Data
题意: 对于16进制数字num,假定 $p_0,p_1,...,p_m$ 在该数字中出现过,如果有 $x = 2^{p_0} + 2^{p_1} + ... + 2^{p_m}$ 且 $x \oplu ...
- c++重载输入输出运算符
1 最好打断点看看哦 2例子 #include <iostream> using namespace std; class Complex2 { public: Complex2(, ) ...
- Identity Server 4 原理和实战(完结)_汇总贴
视频地址:https://www.bilibili.com/video/av42364337 语雀地址:https://www.yuque.com/yuejiangliu/dotnet/solenov ...
- 18.Consent 实现思路介绍
讲一下实现Consent的逻辑 interaction它会根据returnUrl 输入用户名和密码后是在登陆的Controller,登陆完之后呢,会有一个returnUrl returnurl会被带到 ...
- js引用类型的赋值
在开发中,有时候需要将数组或者对象的值赋予其他另一个变量,但是两个变量之间会相互影响,因为在将引用类型的值赋给其他变量时,赋予的其实是内存中的存储地址 var arr = [1,2,3,4,5] va ...
- MFC——ComBox用法大全
Combo Box (组合框)控件很简单,可以节省空间.从用户角度来看,这个控件是由一个文本输入控件和一个下拉菜单组成的.用户可以从一个预先定义的列表里选择一个选项,同时也可以直接在文本框里面输入文本 ...