hdu6034[模拟] 2017多校1
/*hdu6034[模拟] 2017多校1*/
//暴力模拟26个26进制数即可, 要注意进位
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps=1e-;
const int inf=0x3f3f3f3f;
struct node{
char num[];
int ch,high;
}bits[];
const int mod=;
int n,len,pos,mark[],w[],kase=;
char str[];
LL fastpow(LL a,LL b){
LL ret=,x=a;
while(b){
if(b&){
ret=(ret*x)%mod;
}
x=(x*x)%mod;
b>>=;
}
return ret;
}
bool cmp(node a,node b){
if(a.high!=b.high){
return a.high>b.high;
}
else{
for(int i=a.high-;i>=;i--){
if(a.num[i]>b.num[i]){
return ;
}
else if(a.num[i]<b.num[i]){
return ;
}
}
}
return ;
}
LL cal(node& a){
LL ret=;
for(int i=;i<a.high;i++){
if(a.num[i]){
ret=(ret+((LL)a.num[i]*fastpow(26LL,i))%mod)%mod;
}
}
return ret;
}
void solve(){
LL sum=;
sort(bits,bits+,cmp);
for(int i=;i<;i++){
if(bits[i].high) w[bits[i].ch]=-i;
if(mark[bits[i].ch]&&w[bits[i].ch]==){
int pos=i;
while(mark[bits[pos].ch]&&pos) pos--;
for(int j=pos+;j<;j++) w[bits[j].ch]++;
w[bits[pos].ch]=;
}
}
for(int i=;i<;i++){
sum=(sum+w[bits[i].ch]*cal(bits[i]))%mod;
}
printf("Case #%d: %lld\n",kase++,sum);
}
int main(){
while(~scanf("%d",&n)){
memset(bits,,sizeof(bits));
memset(w,,sizeof(w));
memset(mark,,sizeof(mark));
for(int i=;i<;i++) bits[i].ch=i;
for(int i=;i<n;i++){
scanf("%s",str);
len=strlen(str);
mark[str[]-'a']++;
for(int i=;i<len;i++){
pos=len-i-;
bits[str[i]-'a'].high=max(bits[str[i]-'a'].high,pos+);
bits[str[i]-'a'].num[pos]++;
while(pos<&&bits[str[i]-'a'].num[pos]>=){
int k=bits[str[i]-'a'].num[pos]/;
bits[str[i]-'a'].num[pos]-=;
bits[str[i]-'a'].num[++pos]++;
}bits[str[i]-'a'].high=max(bits[str[i]-'a'].high,pos+);
}
}solve();
}
return ;
}
hdu6034[模拟] 2017多校1的更多相关文章
- hdu6136[模拟+优先队列] 2017多校8
有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long ...
- 2017 多校5 hdu 6093 Rikka with Number
2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...
- 2017 多校5 Rikka with String
2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know ...
- 2017 多校4 Wavel Sequence
2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...
- 2017 多校4 Security Check
2017 多校4 Security Check 题意: 有\(A_i\)和\(B_i\)两个长度为\(n\)的队列过安检,当\(|A_i-B_j|>K\)的时候, \(A_i和B_j\)是可以同 ...
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
- 2017 多校2 hdu 6053 TrickGCD
2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...
- 2017 多校1 I Curse Myself
2017 多校2 I Curse Myself(第k小生成树) 题目: 给一张带权无向连通图,该图的任意一条边最多只会经过一个简单环,定义\(V(k)为第k小生成树的权值和\),求出\(\sum_{k ...
- hdu6134[莫比乌斯反演] 2017多校8
/*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...
随机推荐
- UWP开发:自动生成迷宫&自动寻路算法(3)
+ , + ];//0<=x<=12 0<=y<=24 private static Random Rd = new Random(); 首先声明mazeMap存储数据,声明了 ...
- 三、npm start报错:./node_modules/history/esm/history.js解决办法
package.json中的roadhog换为:'^2.5.0-beta.4',删除node_modules文件夹,在执行npm install,npm start.
- HTML_3
html列表 有序列表:在网页上定义一个有编号的内容列表可以用<ol>.<li>配合使用来实现,在网页上生成的列表,每条项目上按1.2.3编号,有序列表在实际开发中较少使用.代 ...
- python之生成器的初识
1. 生成器的定义 生成器的本质就是迭代器.python社区生成器和迭代器是一种 2. 生成器和迭代器区别 迭代器: 都是Python给你提供的已经写好的工具或者通过数据转化得来的 生成器: ...
- C09 指针
目录 指针相关概念 指针变量 null指针 指针的算术运算 指针数组 指向指针的指针 传递指针给函数 从函数返回指针 指针相关概念 变量 如果在程序中定义了一个变量,在对程序进行编译时,系统就会为这个 ...
- Html5的等学习
看了w3c感觉是说明文档,没有详细的说明,然后就去看其他的 html5其实就是在html的基础上做了一些改变,感觉html5的推广还是需要时间的,因为习惯问题,虽然html5有很多很方便的标签如art ...
- SVN:The working copy is locked due to a previous error (二)
之前也碰到过这种问题,但是根本问题不同,解决方案不同. 传送门:SVN:The working copy is locked due to a previous error (二) 本次错误如图: 解 ...
- PHPStorm+XDebug进行调试图文教程
这篇文章主要为大家详细介绍了PHPStorm+XDebug进行调试图文教程,内容很丰富,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 另外如果你们加载不出图片,另外的地址:转载地址https:// ...
- Ubuntu 18.04安装显卡驱动
安装完双系统,我遇到好几次开机或关机有问题,导致我重装了3次系统,第三次我才知道是显卡驱动问题,Ubuntu预装的开源Nvidia驱动太烂了,需要换官方驱动. 把 nouveau 驱动加入黑名单 $s ...
- read design into DC memory