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 ...
随机推荐
- MovieReview—Kingsman THE SECRET SERVICE(王牌特工之特工学院)
Brain Storming Mr. Valentine's Day see excess human beings as the Earth's virus and try to e ...
- javaweb基础(21)_两种开发模式
SUN公司推出JSP技术后,同时也推荐了两种web应用程序的开发模式,一种是JSP+JavaBean模式,一种是Servlet+JSP+JavaBean模式. 一.JSP+JavaBean开发模式 1 ...
- RabbitMQ 学习资料
https://www.rabbitmq.com/getstarted.html http://www.cnblogs.com/luxiaoxun/p/3918054.html http://back ...
- 重温经典之赫夫曼(Huffman)编码
先看看赫夫曼树假设有n个权值{w1,w2,…,wn},构造一个有n个叶子结点的二叉树,每个叶子结点权值为wi,则其中带权路径长度WPL最小的二叉树称作赫夫曼树或最优二叉树. 赫夫曼树的构造,赫夫曼最早 ...
- JWT (JSON WEB Token)正确使用场景
https://www.jianshu.com/p/af8360b83a9f 讲真,别再使用JWT了! ThoughtWorks中国 2017.08.16 08:51* 字数 2882 阅读 7154 ...
- 素材网站——mokuge
- ubuntu16.04安装 java JDK8
安装openjdk1.更新软件包列表: sudo apt-get update 2.安装openjdk-8-jdk: sudo apt-get install openjdk-8-jdk 3.查看ja ...
- classpath、WEB-INF
classpath是指 WEB-INF文件夹下的classes目录(war包),对于springboot项目打包出来的jar包,里面的就是BOOT-INF: 这个demo的源码结构如下: 可见,jav ...
- MYSQL导入数据:Table XXX doesn't exist的解决
数据表为Innodb引擎 data文件夹中存在数据表的frm文件,但在phpmyadmin中看不到这些表,于是采用导入sql文件的方式进行恢复 1.直接导入原数据表的sql文件,原frm文件不删除 出 ...
- 【php】命名空间的影响
命名空间对代码的影响 类(包含抽象类和traits) 接口 常量 函数