Balala Power!

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

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 froma 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
 
//题意:有 n 个小写的字符串,想要把它们变为 26 进制的 0-25 的数字,问 n 个数最大的和为多少?还有,不能有前导0,除非就是0
 
题解:每个字母,在任意位置都会有个权值,统计所有字母的权值,但是只能用大数保存,保存完后。按字母权值排序,最大的赋 24 ,类推,然后考虑可能前导 0 的情况,如果,找到不会作为前导的数后,,关键是,不能交换,而是整体向上平移 1 ,这样才能保证是最大值
 #include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define LL long long
#define MOD 1000000007
#define MX 100100 int n;
int al_n[];
LL num[][MX];
LL quan[];
char temp[MX];
bool ok[]; bool cmp(int a,int b)
{
if (al_n[a]!=al_n[b])
return al_n[a]>al_n[b]; for (int i=al_n[a];i>=;i--)
if (num[a][i]!=num[b][i])
return num[a][i]>num[b][i]; return ;
} int main()
{
int cnt=;
while (scanf("%d",&n)!=EOF)
{
memset(quan,,sizeof(quan));
memset(num,,sizeof(num));
memset(ok,,sizeof(ok)); for (int i=;i<n;i++)
{
scanf("%s",temp);
int len = strlen(temp);
LL k=;
for (int j=len-;j>=;j--)
{
num[temp[j]-'a'][k]++;
k++;
}
if (len!=)
ok[temp[]-'a']=;
} for (int i=;i<;i++)//字母
{
al_n[i]=;
for (int j=;j<MX;j++) //长度
{
if (num[i][j]) al_n[i]=j;
if (num[i][j]>=)
{
int jin = num[i][j]/;
num[i][j+]+=jin;
num[i][j]%=;
}
}
} int alpa[];
for (int i=;i<;i++) alpa[i]=i;
sort(alpa,alpa+,cmp); if (al_n[alpa[]]!=&&ok[alpa[]]==)
{
for (int i=;i>=;i--)
{
if (ok[alpa[i]]==)
{
int sbsb=alpa[i];
for (int j=i+;j<=;j++)
alpa[j-]=alpa[j];
alpa[]=sbsb;
break;
}
}
} LL ans = ;
LL qqq = ;
for (int i=;i<;i++)
{
int zimu = alpa[i];
if (al_n[zimu]==) continue;
LL tp=qqq;
for (int j=;j<=al_n[zimu];j++)
{
ans = (ans + (tp * num[zimu][j])%MOD)%MOD;
tp=(tp*)%MOD;
}
qqq--;
}
printf("Case #%d: %lld\n",cnt++,ans);
}
return ;
}

Balala Power!(大数+思维)的更多相关文章

  1. HDU 6034 17多校1 Balala Power!(思维 排序)

    Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...

  2. HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1

    /* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...

  3. HDU 6034 Balala Power!【排序/进制思维】

    Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java ...

  4. 2017 多校训练 1002 Balala Power!

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

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

  6. hdu 6034 B - Balala Power! 贪心

    B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...

  7. hdu 6034 Balala Power!

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  9. HDU 6034 Balala Power!(贪心+排序)

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. 【转】Spring Annotation 详解

    (1) .<context:component-scan base-package="*.*" /> 该配置隐式注册了多个对注解进行解析的处理器,如: Autowire ...

  2. Git——使用gitignore建立项目过滤规则

    在进行协作开发代码管理的过程中,常常会遇到某些临时文件.配置文件.或者生成文件等,这些文件由于不同的开发端会不一样,如果使用git add . 将所有文件纳入git库中,那么会出现频繁的改动和push ...

  3. Java 遍历一个对象的属性 将非空属性赋值给另一个对象

    //将origin属性注入到destination中 public <T> void mergeObject(T origin, T destination) { if (origin = ...

  4. iOSQuart2D绘图之UIImage简单使用

    代码地址如下:http://www.demodashi.com/demo/11609.html 人生得意须尽欢,莫使金樽空对月. 天生我材必有用,千金散尽还复来. 前记 说到UIImage大家都不会感 ...

  5. 改动图片exif信息

    我们先了解一下EXIF: EXIF能够附加于JPEG.TIFF.RIFF等文件之中.为其添加有关数码相机拍摄信息的内容和索引图或图像处理软件的版本号信息. 全部的JPEG文件以字符串"0xF ...

  6. python challenge - orc.py

    http://www.pythonchallenge.com/pc/def/ocr.html recognize the characters. maybe they are in the book, ...

  7. Linux-信号详解

    1.Linux支持的所有信号: $ kill -l ) SIGHUP ) SIGINT ) SIGQUIT ) SIGILL ) SIGTRAP ) SIGABRT ) SIGBUS ) SIGFPE ...

  8. Spring事务的传播行为 @Transactional

    Spring事务的传播行为http://blog.csdn.net/cuker919/article/details/5957209 在service类前加上@Transactional,声明这个se ...

  9. redis实践一些要注意的事项

    不要放垃圾数据,及时清理无用数据实验性的数据和下线的业务数据及时删除; key尽量都设置过期时间对具有时效性的key设置过期时间,通过redis自身的过期key清理策略来降低过期key对于内存的占用, ...

  10. Angular 2 组件之间如何通信?

    组件之间的共享可以有好几种方式 http://learnangular2.com/outputs/ 实例参考https://angular.io/docs/ts/latest/cookbook/com ...