2017 Multi-University Training Contest - Team 1 Balala Power!
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 26hilariously.
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 <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
const int mod = 1e9+;
const int maxn=1e5+;
struct Node{
int ans[maxn+];
int id;
bool operator < (const Node &a) const
{
for(int i = maxn-; i >= ; i--)
{
if(ans[i] > a.ans[i]) return ;
else if(ans[i] < a.ans[i]) return ;
else ;
}
}
}node[];
long long x[maxn];
void init(){
x[]=;
for(int i=;i<=maxn;i++){
x[i]=x[i-]*;
x[i]%=mod;
}
x[maxn]=;
}
bool Sort(Node a,Node b){
for(int i=;i<maxn;i++){
if(a.ans[i]<b.ans[i]){
return ;
}else if(a.ans[i]>b.ans[i]){
return ;
}
}
}
int flag[maxn];
int zero[maxn];
int cnt=;
int main(){
init();
int n;
while(~scanf("%d",&n)){
memset(flag,-,sizeof(flag));
memset(node,,sizeof(node));
memset(zero,,sizeof(zero));
char a[maxn];
for(int i=;i<n;i++){
scanf("%s",a);
int len=strlen(a);
if(len!=){
zero[a[]-'a']=;
}
for(int i=;i<len;i++){
node[a[i]-'a'].ans[len-i-]++;
}
}
// cout<<"A"<<endl;
for(int i=;i<;i++){
for(int j=;j<maxn;j++){
if(node[i].ans[j]>=){
node[i].ans[j+]+=node[i].ans[j]/;
node[i].ans[j]%=;
}
}
node[i].id=i;
}
//cout<<"B"<<endl;
sort(node,node+);
for(int i=;i<;i++){
flag[node[i].id]=-i-;
} for(int i=;i<;i++){
if(zero[node[i].id]&&flag[node[i].id]==){
for(int j=;j>=;j--){
if(zero[node[j].id]==){
for(int k=;k>=j+;k--){
flag[node[k].id]=flag[node[k-].id];
}
flag[node[j].id]=;
break;
}
}
break;
}
}
long long ans=;
for(int i=;i<;i++){
for(int j=;j<maxn;j++){
ans+=(x[j]*node[i].ans[j]*flag[node[i].id]%mod)%mod;
}
}
printf("Case #%d: %lld\n",cnt++,ans%mod);
}
return ;
}
2017 Multi-University Training Contest - Team 1 Balala Power!的更多相关文章
- 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 ...
- 2017 Multi-University Training Contest - Team 1 1002&&hdu 6034
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】
Dying Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】
Ch’s gift Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】
Big binary tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】
Colorful Tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
随机推荐
- [CPP] Coding Style
C++ Coding Style C++很多强大的语言特性导致它的复杂,其复杂性会使得代码更容易出现bug.难于阅读和维护. 由于,本人有一点点代码洁癖,所以依照Google的C++编程规范<G ...
- POJ 1611 The Suspects (并查集+数组记录子孙个数 )
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 24134 Accepted: 11787 De ...
- POJ2492 A Bug's Life —— 种类并查集
题目链接:http://poj.org/problem?id=2492 A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Su ...
- valid No such filter: 'drawtext'"
libfreetype is missing. You'll have to rebuild FFmpeg with this library or disable overlays. --enabl ...
- Python模块:os
OS模块常用用法: os.name() #判断当前使用的系统环境,windows则返回 ‘nt’,Linux则返回‘posix’ os.getcwd() #显示当前目录 os.listdir() #以 ...
- iptables 端口映射
一.环境和要实现功能 PC1的网络设置如下: eth0 192.168.0.29 内网 eth1 219.239.11.22 外网 PC2的网络设置则为:192.168.0.21 内网 我 ...
- android自动化测试之uiautomator
1.通过monkeyrunner.bat monkey_record.py启动MonkeyRecorder进行拿到各个控件的坐标(要连上手机才可以启动) 2.也可以通过uiautomatorvie ...
- ceph学习之pool
pool是ceph存储数据时的逻辑分区,它起到namespace的作用.其他分布式存储系统,比如Mogilefs.Couchbase.Swift都有pool的概念,只是叫法不同.每个pool包含一定数 ...
- office2016出现 此功能看似已中断 并需要修复
- 2.1-2.2 Hive 中数据库(Table、Database)基本操作
官网文档:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL 一.create table 1.官方字段 # # C ...