HDU 6034 Balala Power!(大数进制)
2017-07-25 21:28
337 查看
Balala Power!Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1317 Accepted Submission(s): 229 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 from a to z into each number ranged from 0 to 25, but each 4000 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 Source 2017 Multi-University Training Contest - Team 1 |
题意:
a-z分别可变为0-25,给你n个字符串,把变成26进制的数,加起来合最大。每个字符串除了单个0,没有前置0。
point:
算出各个字母的价值,开一个char数组(int数组会报错!耽误了好久)来存下字母在第几位上出现了几次,因为字符串很长,所以要开char[100007]。并且由于26进制,在某位上超过了26就进1清零,这个和大数运算相同。
在根据每个char数组代表的价值来进行排序。注意有些字母是不能为0的。
以上在比赛中都实现了,由于一些小细节方面就一直WA。
所以要先确定哪个是0,当然是从价值最小的开始找,找到则标记。
然后在从价值最大的开始找,分别赋值从25到1,但要注意0位置的上下。
可以先打个 26^1-100000的表。计算起来比较方便。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
#define rt x<<1|1
#define lt x<<1
#define LL long long
const LL p = 1e9+7;
LL m[100000+5];
const int maxn=100000+7;
int vis[26];
struct node
{
int flag;
char num[maxn];
}num[27];
void init()
{
m[0]=1;
LL now=1;
for(int i=1;i<=100000;i++)
{
now*=26;
m[i]=now%p;
now=now%p;
}
}
bool cmd(node a,node b)
{
for(int i=maxn-1;i>0;i--)
{
if(a.num[i]!=b.num[i])
{
return a.num[i]>b.num[i];
}
else ;
}
return a.num[0]>b.num[0];
}
int main()
{
int n;
init();
int pp=0;
while(~scanf("%d",&n))
{
char str[maxn];
for(int i=0;i<26;i++)
{
num[i].flag=i;
vis[i]=0;
for(int j=0;j<maxn;j++) num[i].num[j]=0;
}
for(int i=1;i<=n;i++)
{
scanf("%s",str);
int l=strlen(str);
if(l!=1) vis[str[0]-'a']=1;
for(int j=0;j<l;j++)
{
int x=str[j]-'a';
int y=l-j-1;
num[x].num[y]++;
while(num[x].num[y]==26)//防止一直进位,用while-这里很重要,不仔细就wa了
{
num[x].num[y++]=0;
num[x].num[y]++;
}
}
}
sort(num,num+26,cmd);
LL ans = 0;
int f=-1;
for(int i=25;i>=0;i--)
{
if(!vis[num[i].flag])
{
f=i;
break;
}
}
for(int i=0;i<=25;i++)
{
if(i==f);
else if(i<f)
{
LL haha=25-i;
for(int j=maxn;j>=0;j--)
{
(ans+=(LL)haha*m[j]*num[i].num[j])%=p;
}
}
else
{
LL haha=25-i+1;
for(int j=maxn;j>=0;j--)
{
(ans+=(LL)haha*m[j]*num[i].num[j])%=p;
}
}
}
printf("Case #%d: %lld\n",++pp,ans);
}
}
相关文章推荐
- HDU 6034 Balala Power! 【模拟】【大数高精度】
- HDU 6034 Balala Power!(进制)
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- hdu-6034-Balala Power!
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- hdu 6034 Balala Power! (2017 Multi-University Training Contest - Team 1)
- HDU 6034 Balala Power!
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- HDU 6034 Balala Power! (位权排序)
- HDU 6034 Balala Power! 2017多校1.2
- hdu-6034-Balala Power!
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- HDU-6034 Balala Power! - 2017 Multi-University Training Contest - Team 1(贪心)
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- HDU 6034 Balala Power!(贪心)
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- 2017 杭电多校联赛 1002 Balala Power!(数字替换字母)HDU 6034
- HDU 6034-(2017多校第一场 Balala Power!)(贪心)
- HDU 6034 Balala Power!
- HDU-6034 Balala Power!