hdu6034

找了一早上bug,真是被自己气死
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
const long long mod=1e9+7;
const int maxn=1e5+7;
int maxj;
struct node{
	int id;
	int num[maxn]={0};
	// bool operator < (const node &b)const{
	// 	for(int j=maxj;j>=0;j--){
	// 		if(b.num[j]!=num[j]){
	// 			return num[j]>b.num[j];
	// 		}
	// 		return 0;
	// 	}
	// }
}a[30];
bool cmp(node u,node v){
	for(int j=maxj;j>=0;j--){
		if(u.num[j]!=v.num[j])
			return u.num[j]>v.num[j];
	}
	return u.num[0]>v.num[0];
}
bool book[30];
long long  weight[maxn];
char s[maxn];
int main(){
	//freopen("test.txt","r",stdin);
	int n;
	int kase=0;
	int i,j;
	weight[0]=1;
	for(i=1;i<=100000;i++){
		weight[i]=(weight[i-1]*26)%mod;
		weight[i]%=mod;
		//printf("%d %lld\n",i,weight[i]);
	}
	maxj=0;
	while(~scanf("%d",&n)){
		//printf("%d",n);
		for(i=0;i<26;i++){
			a[i].id=i;
			book[i]=false;
			for(j=0;j<=maxj;j++){
				a[i].num[j]=0;
			}
		}
		maxj=0;
		kase++;
		for(i=0;i<n;i++){
			scanf("%s",s);
			int len=strlen(s);
			// puts(s);
			// printf("strlen %d\n",len);
			int jj;
			// for(j=0,jj=len-1;jj>=0;j++,jj--){
			// 	int t=s[jj]-'a';
			// 	a[t].num[j]++;
			// 	if(jj==0)
			// 		book[t]=1;
			// 	maxj=max(j,maxj);
			// }
			j=0;
			for(jj=len-1;jj>=0;jj--){
				int t=s[jj]-'a';
				a[t].num[j]++;
				//printf("%c %d\n",s[jj],j);
				if(jj==0)
					book[t]=true;
				maxj=max(j,maxj);
				j++;
			}
		}
		for(i=0;i<26;i++){
			for(j=1;j<=maxj;j++){
				a[i].num[j]+=a[i].num[j-1]/26;
				a[i].num[j-1]%=26;
			}
			j=maxj;
			//printf("j:%d\n",j);
			while(a[i].num[j]>=26){
				a[i].num[j+1]+=a[i].num[j]/26;
				a[i].num[j]%=26;
				j++;
				maxj=max(j,maxj);
			}
		}
		//printf("%d\n",maxj);
		sort(a,a+26,cmp);
		// for(i=0;i<26;i++){
		// 	printf("%c:",'a'+a[i].id);
		// 	for(j=0;j<=maxj;j++){
		// 		printf("%d ",a[i].num[j]);
		// 	}
		// 	printf("\n");
		// }
		if(book[a[25].id]){
			for(i=25;i>=0;i--){
				if(book[a[i].id]==false)
					break;
			}
			a[26]=a[i];
			for(;i<=25;i++){
				a[i]=a[i+1];
			}
		}
		long long ans=0;
		for(i=0;i<26;i++){
			for(j=0;j<=maxj;j++){
				if(a[i].num[j]!=0){
					ans+=((25-i)*weight[j]*a[i].num[j])%mod;
					//printf("%c %d %d %d\n",a[i].id+'a',25-i,i,weight[j]);
					ans%=mod;
				}
			}
		}
		printf("Case #%d: %lld\n",kase,ans);
	}
	return 0;
}

Balala Power!

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3199    Accepted Submission(s): 725


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 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. (1n100000)

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
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6044  6043  6042  6041  6040 
 

Statistic |  Submit |  Discuss | Note
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值