Balala Power!(大数+思维)
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 714 Accepted Submission(s): 117

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.
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 <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!(大数+思维)的更多相关文章
- HDU 6034 17多校1 Balala Power!(思维 排序)
Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...
- HDU 6034 Balala Power!【排序/进制思维】
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java ...
- 2017 多校训练 1002 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!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 6034 B - Balala Power! 贪心
B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...
- hdu 6034 Balala Power!
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
随机推荐
- 右键添加在siblime中打开选项
siblime text安装完成之后没有右键打开的快捷方式,对于开发者来说每次用siblime打开文件比较繁琐. 下面教程可以让大家解决这个问题 首先点击开始--运行,输入regedit,(win7系 ...
- Python Socket API 笔记
将上节中的C#该成Python版的容易程度大大超出了我的意料之外.从来没有发现,仅仅用灰尘简单的几句话就实现了该程序的主要功能,可见python的简易和强大之处.这里先对SocketAPI 做一下总结 ...
- JAVA 的IO操作实例
实例要求: 1,加法操作: 键盘输入两个数字,完成加法操作.因为从键盘接收过来的内容都是通过字符串形式存放的,所以此时直接通过包装类 Integer将字符串变为基本数据类型. 2,菜单显示: 采用的知 ...
- 虚拟机下安装CentOS无法上网的解决方式
我使用VMware虚拟机安装Ubuntu和CentOS,都使用NAT模式连接网络,可是Ubutun能够正常上网,而CentOS不能连接到网络. 原来Centos7默认是不启用有线网卡的.须要手动开启. ...
- Linux下使用Fastboot给手机刷ROM
前言 一直在刷机.失败.刷机.失败中,还好今天有个任务能够使用fastboot刷机.好开心,最终不用切换系统了.(话说好久没有写代码了,身为一个互联网程序猿,不写代码我easy紧张). 开发环境 Ub ...
- python challenge答案参考
Solutions to python challenge. http://garethrees.org/2007/05/07/python-challenge/ https://github.com ...
- Jenkins插件开发资料
原文地址:http://www.ciandcd.com/?p=181 Jenkins plugin 开发: Document http://hudson-ci.org/docs/index.html ...
- in App Purchases一个注意事项
在completeTransaction中通过transaction.originalTransaction.payment.productIdentifier得到的productIdentifier ...
- Django学习之模板标签和变量
safe过滤器和{% autoescape %}标签 首先看这样一个例子: views.py中: c = '<h3>更上一层楼</h3>' render(request,'te ...
- Linux下同步模式、异步模式、阻塞调用、非阻塞调用总结
转自:http://www.360doc.com/content/13/0117/12/5073814_260691714.shtml 同步和异步:与消息的通知机制有关. 本质区别 现实例子 同步模式 ...