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) ...
 
随机推荐
- pthread_barrier_init,pthread_barrier_wait简介(转)
			
pthread_barrier 系列函数在<pthread.h>中定义,用于多线程的同步,它包含三个函数: --pthread_barrier_init() --pthread_barri ...
 - MapReduce源代码分析之JobSubmitter(一)
			
JobSubmitter.顾名思义,它是MapReduce中作业提交者,而实际上JobSubmitter除了构造方法外.对外提供的唯一一个非private成员变量或方法就是submitJobInter ...
 - C语言-一个fopen函数中未使用二进制模式(b)引发的血案
			
转自:http://blog.csdn.net/hinyunsin/article/details/6401854 最近写了一个网络文件传输模块,为了让这个模块具有更好的移植性,我尽量使用C标准IO ...
 - lua与c++ 中布尔布bool值对应关系
			
lua代码返回值为真c++ lua_toboolean 返回一个 int lua true = 1 false = 0 c++给lua返回 lua_pushboolean 1 = true 0 = ...
 - UnicodeEncodeError: ‘gbk’ codec can’t encode character u’\u200e’ in position 43: illegal multibyte sequence
			
[问题] python中已获取网页: http://blog.csdn.net/hfahe/article/details/5494895 的html源码,其时UTF-8编码的. 提取出其标题部分: ...
 - ActiveMQ与MSMQ的异同
			
http://www.cnblogs.com/luluping/archive/2010/11/03/1867841.html 目前常用的消息队列组建无非就是MSMQ和ActiveMQ,至于 ...
 - C++ 内存泄漏
			
1. 内存泄漏: 在计算机科学中,内存泄漏指由于疏忽或错误造成程序未能释放已经不再使用的内存的情况. 内存泄漏并非指内存在物理上的消失,而是应用程序分配某段内存后,由于设计错误,导致在释放该段内存之前 ...
 - 125. Valid Palindrome【easy】
			
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
 - Nginx HttpSubModule sub_filter模块的过滤功能
			
Nginx HttpSubModule sub_filter模块的过滤功能 发表于2年前(2013-08-05 10:39) 阅读(1481) | 评论(0) 0人收藏此文章, 我要收藏 赞0 5 ...
 - html+css+JavaScript贪吃蛇
			
写文记录一下最近新完成的贪吃蛇游戏案例,用到了html.css和JavaScript,难度不高,适合刚入坑的同学练习,欢迎大家交流. 下面贴源码: <!DOCTYPE html> < ...