首页 技术 正文
技术 2022年11月20日
0 收藏 381 点赞 4,191 浏览 2473 个字

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.

 InputThe 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) OutputFor 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 Input1a2aabb3abaabc Sample OutputCase #1: 25Case #2: 1323Case #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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898