HDU 6034 Balala Power! —— Multi-University Training 1

Talented Mr.Tang has nn 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 2626 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+7109+7.
Input
The input contains multiple test cases.
Output
For each test case, the first line contains one positive integers nn, the number of strings. (1≤n≤100000)
Each of the next nn lines contains a string sisi consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤1e6)e
OutputFor each test case, output " Case #xx: yy" in one line (without quotes), where xxindicates the case number starting from 11 and yy 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
题目大意:用26个字母表示26进制数中的1~26,并且给你n个字符串,以26进制从字符串转化为数字,问这些数字之和最大能有多少(以十进制输出)。为保证数据正确,其中必存在至少一个字母是代表了0。
思路:模拟。首先每个字母代表的数未知,但由于每个字符在字符串的位置是已知的,我们就可以求出每个字母从26进制转化十进制时的“系数”(即像26^a1+26^a2+26^a3……的数),用数组存储26进制数,在求和时考虑进位,去掉必为0的字母,然后对按26进制数的大小对数组排序,最后就能够求和解出答案了。。。比赛的时候是用的字符串存26进制,理论上也是可以做的,但是因为进位的姿势不对(一边加一边进位,先全部加完再进位才是正确的)导致TLE/(ㄒoㄒ)/
代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
#define MOD 1000000007
#define MAXN 100010
using namespace std;
long long num[][MAXN],w[];
long long sum[];
long long a[MAXN];
int u;
char ss[MAXN];
bool vis[];
bool cmp(int s, int t)
{
for(int i=u-;i>=;i--){
if(num[s][i]!=num[t][i])
return num[s][i]<num[t][i];
}
return ;
}
int main()
{
a[]=;
for(int i=;i<MAXN-;i++)
a[i]=*a[i-]%MOD; int n;
int z=;
while(~scanf("%d", &n))
{
u=;
memset(num, , sizeof(num));
memset(sum, , sizeof(sum));
memset(vis,false,sizeof(vis));
int wei,p;
for(int i=;i<n;i++){
scanf("%s", ss);
int l=strlen(ss);
if(l>)
vis[ss[]-'a']=true; for(int j=;j<l;j++){
p=ss[j]-'a';
wei=l--j;
num[p][l--j]++;
sum[p]+=a[wei];
sum[p]%=MOD;
}
u=max(u, l);
}
for(int i=;i<;i++){
for(int j=;j<u;j++){
num[i][j+]=num[i][j+]+num[i][j]/;
num[i][j]=num[i][j]%;
}
while(num[i][u])
{
num[i][u+]+=num[i][u]/;
num[i][u++]%=;
u++;
}
w[i]=i;
}
int cnt=-;
sort(w, w+, cmp);
for(int i=;i<;i++){
if(!vis[w[i]]){
cnt=w[i];
break;
}
}
//cout<<cnt<<endl;
int res=,x=;
for(int i=;i>=;i--){
if(cnt!=w[i]){
res+=(long long)(x--)*sum[w[i]]%MOD;
res%=MOD;
} }
z=z+;
printf("Case #%d: %lld\n",z,res);
}
}
HDU 6034 Balala Power! —— Multi-University Training 1的更多相关文章
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...
- 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 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 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 ...
- HDU 6034 Balala Power! (贪心+坑题)
题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后 ...
- 6034 Balala Power! (17多校)
题目大意:给出的字符串,每个字符建立一种与0-25的对应关系.然后每个字符串看成是一个26进制的数.问能获得的数的总和的最大值.(最后对1e9+7取模). 题目思考:把每个字符的贡献值看做一个26进制 ...
- hdu 6034 B - Balala Power! 贪心
B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...
随机推荐
- Docker 官网文档翻译汇总
官方文档地址 Guide Docker 入门 Docker 入门教程 方向和设置 容器 服务 swarm 集群 stack 部署应用 概述 用 Docker 进行开发 在 Docker 上开发应用 应 ...
- (appium+python)UI自动化_03_元素定位工具
前言 在UI自动化过程中,需要对手机app上的元素进行定位,然后进一步编写自动化脚本操作app.定位元素首先需要定位工具来辅助查看页面元素.小编常用的定位工具有2种,分别是uiautomatorvie ...
- Windows系统CVE整理
CVE-2018-8420(RCE) 受影响版本: Microsoft Windows 10 Version 1607 for 32-bit Systems Microsoft Windows 10 ...
- EasyUI在子tab基础上再打开新的tab标签页
var title = "xxxx"; var content = '<iframe scrolling="auto" frameborder=" ...
- 图解Http阅读笔记(一)
1.网络基础 TCP/IP 1.1TCP /IP 协议族 计算机与网络设备要相互通信,双方就必须基于相同的方法.比如,如何探测到通信目标.由哪一边先发起通信.使用哪种语言进行通信.怎样结束通信等规 ...
- Java实现红黑树
转自:http://www.cnblogs.com/skywang12345/p/3624343.html 红黑树的介绍 红黑树(Red-Black Tree,简称R-B Tree),它一种特殊的二叉 ...
- 前端最常用的跨域方式--jsonp
jsonp通过动态创建script标签的方式来实现跨域通信.原理是浏览器允许html标签在不同的域名下加载资源. <script> var script = document.create ...
- python常用模块---collections、time、random、os、sys、序列号模块
collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...
- 77.LRU Cache(最近最久未使用算法)
Level: Hard 题目描述: Design and implement a data structure for Least Recently Used (LRU) cache. It sh ...
- C# 引用类型的深度拷贝帮助类
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Lin ...