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) ...
随机推荐
- 倍福TwinCAT(贝福Beckhoff)应用教程13.1 TwinCAT控制松下伺服 NC高级
本节主要演示了使用自定义函数实现电机的运动(梯形曲线和S曲线都有实现),这里的JOG+和JOG-,针对单个关节实现了PTP的运动(跟贝福的MoveAbsolute功能块实现效果一致),在此没有介绍运动 ...
- Apache代理80端口
找到Apache下的conf\extra\httpd-vhosts.conf文件 新增以下内容于合适位置 ↓表示80端口 <VirtualHost *:80> ServerAdmin * ...
- iDempiere = OSGi + ADempiere 一款ERP&CRM&SCM系统、助力中小企业发展
怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ iDempiere = OSGi + ADempiere 一款ERP&CRM&a ...
- Android.KungFu手机病毒原理及清理方法
原文链接:http://jingyan.baidu.com/article/363872ec8ad56b6e4ba16fb1.html Android.KungFu手机病毒清理方法 浏览:3333 | ...
- Autofc与Mvc,WebForm,Weiapi,Owin整合源码分析
主要分析一下的几个项目: Autofac.Integration.Mvc Autofac.Integration.WebApi Autofac.Integration.Owin Autofac.Int ...
- Android AIDL Service 跨进程传递复杂数据
黑夜 黑夜给了我黑色的眼睛,我却用它寻找光明~ 传值方式 AIDL是同意跨进程传递值的,一般来说有三种方式: - 广播:这样的算是比較常见的一种方式了,传递小数据不错 - 文件:这个是保存到文件里.然 ...
- Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache.
关闭VS再来就好了
- MySql(零):Linux(CentOS7)下安装和配置MySQL5.7.20(安装包安装)
一.下载安装包 1.在官网下载MySQL5.7安装包 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz. 下载地址:https://dev.mysql.com/do ...
- Angularjs学习笔记10_directive3
1. restrict M 使用模板 A 属性扩展 2. template,templateUrl,$templateCache 模板缓存 //注射器加载完所有模块时,此方法执行一 ...
- python模块学习之json
更多信息请参考官网地址: https://docs.python.org/3.6/library/json.html 19.2. json - JSON编码器和解码器 Source code: Lib ...