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. rails手脚架(scaffold)功能

    scaffold是一个高速开发rails应用的代码框架.能够使用一条命令实现CRUD操作. 1: 创建一个应用 rails new scaffoldapp cd scaffoldapp rails s ...

  2. Request.Cookies使用方法分析

    本文章介绍了Request.Cookies的基本的语法和使用方法. 而且通过演示样例分析了Request.Cookies的使用过程. Request.Cookies方法能够检索Cookies 集合中的 ...

  3. Java 中字符串的格式化

    1.格式字符串语法 产生格式化输出的每个方法都需要格式字符串 和参数列表.格式字符串是一个String,它可以包含固定文本以及一个或多个嵌入的格式说明符.请考虑以下示例: Calendar c = C ...

  4. Ubuntu git 安装、生成sshkey、克隆、切换分支

    #1.安装git apt-get install git; #2生成公钥私钥文件 2.配置git账户: git config --global user.name "yourname&quo ...

  5. react-navigation 页面跳转 及 传参

    1.配置路由 export const AppNavigator = createStackNavigator ( { Guide: { // 引导页 screen: GuidePage }, Lau ...

  6. Android-LinearLayout布局技巧(二)

    先来看看图: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...

  7. Loadrunner Analysis之Web Page Diagnostics

    Loadrunner Analysis之Web Page Diagnostics 分类: LoadRunner 性能测试 2012-12-31 18:47 1932人阅读 评论(2) 收藏 举报 di ...

  8. WP8控件进度条(ProgressBar)的使用

    --前台代码 <Grid x:Name="ContentPanel"  Grid.Row="1" Margin="0,0,24,0"& ...

  9. PHP-深入理解Opcode缓存

    1.什么是opcode缓存? 当解释器完成对脚本代码的分析后,便将它们生成可以直接运行的中间代码,也称为操作码(Operate Code,opcode).Opcode cache的目地是避免重复编译, ...

  10. sql DATEPART() MONTH() convert() cast() dateadd() DATEDIFF() with(nolock)

    DATEPART() 函数用于返回日期/时间的单独部分,比如年.月.日.小时.分钟等等. 语法 DATEPART(datepart,date) date 参数是合法的日期表达式.datepart 参数 ...