Balala Power!

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

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 nextlines 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
题意:给出一些字符串,由小写字母构成,用26(0-25)进制的数代替字母,不同字母不能相同。求转化后的26进制数最大为多少,结果对1e9+7取模。长度大
于1的串结果不能有前导0,除了单个字符.
【思路】:统计每个字符所在位,和其中的个数,以a字符为例。统计结果为
a[0]26^0+a[1]26^1+a[2]x2+.....+a[n-1]26^(n-1),其中a[i]代表a在第i位出现的次数
转化使得a[i]<26,变成x[0]26^0+x[1]26^1+...+x[n-1]26^(n-1)+x[n]26^(n)+...,
每个字符如此操作,谁取得最高位,这个字符就为25,第二高位为24,......,
排个序就可以了。如果出现前导0,从排序好的序列,从前往后找到可以为0的第一个字符,因为能作为0,它的x[i]26^(i)要越小,结果越大
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const double PI=acos(-1.0);
const double eps=0.0000000001;
const int N=+;
const ll mod=1e9+;
ll num[][N];
ll sum[N];
ll val[N];
int vis[N];
int a[N];
int t;
void init(){
val[]=;
for(int i=;i<=N;i++){
val[i]=val[i-]*%mod;
}
}
bool cmp(int a,int b){
for(int i=t-;i>=;i--){
if(num[a][i]!=num[b][i])
return num[a][i]<num[b][i];
}
}
int main(){
int n;
int tt=;
init();
string s;
while(scanf("%d",&n)!=EOF){
t=;
memset(vis,,sizeof(vis));
memset(num,,sizeof(num));
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++){
cin>>s;
int len=s.size();
if(len>){
vis[s[]-'a']=;
}
for(int j=;j<len;j++){
num[s[j]-'a'][len-j]++;
sum[s[j]-'a']+=val[len-j];
sum[s[j]-'a']%=mod;
}
t=max(t,len);
}
for(int i=;i<;i++){
for(int j=;j<=t;j++){
num[i][j+]+=num[i][j]/;
num[i][j]%=;
}
t++;
while(num[i][t]){
num[i][t+]+=num[i][t]/;
num[i][t++]%=;
}
a[i]=i; }
sort(a,a+,cmp);
int flag;
for(int i=;i<;i++){
if(vis[a[i]]==){
flag=a[i];
break;
}
}
ll ans=;
int x=;
for(int i=;i>=;i--){
if(a[i]!=flag){
ans=ans+((x--)*sum[a[i]]%mod);
ans=ans%mod;
}
}
printf("Case #%d: %d\n",tt++,ans);
}
}

2017 Multi-University Training Contest - Team 1 1002&&hdu 6034的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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) ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】

    KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. Android studio 中R.menu的创建

    对于Android开发中的menu没有声明的情况: 首先,将鼠标定位到红色的menu上面, 然后,Alt+enter组合键,建立文件menu, 然后将以下代码复制进去: <item androi ...

  2. Android基础TOP3_1:纵横屏切换

    在Res下建立layout-port文件夹  为竖屏时加载的界面: 建立layout-land 文件夹 为横屏加载的界面

  3. jQuery——开关灯

    js对象与jquery对象的相互转化: 1.$(js对象) 2.$(selector).get(索引).$(selector)[索引] <!DOCTYPE html> <html l ...

  4. Python语言之类

    1.一个空类 #Filename : emptyclass.py class Empty: pass e = Empty() print( e ) #<__main__.Empty object ...

  5. SQLServer bigint 转 int带符号转换函数(原创)

    有一个需求是要在一个云监控的状态值中存储多个状态(包括可同时存在的各种异常.警告状态)使用了位运算机制在一个int型中存储. 现在监控日志数据量非常大(亿级别)需要对数据按每小时.每天进行聚合,供在线 ...

  6. Java程序员2016年终总结

    回顾2016年, 很庆幸,自己能在2016年年尾找到一份满意的web后台开发工作.这也是我学习编程以来第一份开发工作,我很是珍惜. 还记得大三接触了Java的JFrame编写的坦克大战之后,就对编程产 ...

  7. (转)Hibernate的优化方案

    http://blog.csdn.net/yerenyuan_pku/article/details/70768603 HQL优化 使用参数绑定  使用绑定参数的原因是让数据库一次解析SQL,对后续的 ...

  8. Html test

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  9. illumina测序原理

    一些常用基本概念的介绍: flowcell流动池 是指Illumina测序时,测序反应发生的位置,1个flowcell含有8条lane lane通道 每一个flowcell上都有8条泳道,用于测序反应 ...

  10. Django - 视图获取请求头

    1.urls.py(url和函数对应关系) 2.通过request.evniron,返回request的所有信息,用索引的方式,获取用户请求头信息. 3.也可以通过key,value方式,来展示请求头 ...