【BubbleCup X】G:Bathroom terminal
一个hash的题
对?出现位置直接暴力枚举,然后hash判断下,扔进map里
cf的评测机跑的针tm块
#include<bits/stdc++.h>
const int N=;
const int bas=;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int n,m,cnt,len,ans;
char s[N],ss[N];
map<ull,int>mps[N];
map<pair<int,ull>,int>mps2;
int hs[N],a[N];
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
inline void check(){
for(int i=;i<=cnt;i++)if(a[i]==-)s[hs[i]]='?';else s[hs[i]]='a'+a[i];
ull h=;int tmp=;
for(int i=;i<=len;i++)if(s[i]!='?')++tmp,h=h*bas+s[i]-'a';
if(!mps2.count(make_pair(tmp,h))){ans+=mps[tmp][h];mps2[make_pair(tmp,h)]=;}
}
inline void dfs(int now){
if(now==cnt+){check();return;}
for(int i=-;i<=;i++)a[now]=i,dfs(now+);
}
int main(){
n=read();m=read();
for(int i=;i<=n;i++){
scanf("%s",s+);len=strlen(s+);
ull h=;for(int j=;j<=len;j++)h=h*bas+s[j]-'a';
mps[len][h]++;
}
while(m--){
scanf("%s",s+);len=strlen(s+);cnt=;
for(int j=;j<=len;j++)if(s[j]=='?')hs[++cnt]=j;ans=;
mps2.clear();dfs();
printf("%d\n",ans);
}
}
【BubbleCup X】G:Bathroom terminal的更多相关文章
- Codefroces 852 G. Bathroom terminal
G. Bathroom terminal Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to p ...
- 【IntellJ IDEA】idea的Terminal窗口中文乱码 解决方法
在操作git命令在windows上的idea中的terminal窗口时,总是出现中文乱码的问题 本开始以为是git乱码的问题,如果是GIt中文乱码,解决方案:https://www.cnblogs.c ...
- 【亲测】<g++/gcc>CentOS下g++: command not found问题的解决(c++环境安装)
CentOS下g++: command not found问题的解决 2017年02月27日 18:09:06 阅读数:5174 标签: centosgcc 更多 个人分类: 问题分析 版权声明: ...
- 【BubbleCup X】D. Exploration plan
这个题首先一眼能看出二分答案…… 毕竟连可爱的边界都给你了. 下面就是怎么check 首先预处理跑一遍floyed,预处理出最短路. 用网络流判断能否达到即可. #include<bits/st ...
- 【ASC 23】G. ACdream 1429 Rectangular Polygon --DP
题意:有很多棍子,从棍子中选出两个棍子集合,使他们的和相等,求能取得的最多棍子数. 解法:容易看出有一个多阶段决策的过程,对于每个棍子,我们有 可以不选,或是选在第一个集合,或是选在第二个集合 这三种 ...
- 【CodeForces 602B】G - 一般水的题2-Approximating a Constant Range
Description When Xellos was doing a practice course in university, he once had to measure the intens ...
- 【BubbleCup X】F:Product transformation
按照题解的规律,首先能看出前面每个数幂次的性质. 然后发掘约数的性质 #include<bits/stdc++.h> ; typedef long long ll; using names ...
- 论文阅读笔记:【Transforming Auto-encoders】
[Transforming Auto-encoders]: G E Hinton, A Krizhevsky, S D Wang. Transforming auto-encoders[C]. //I ...
- 【Havel 定理】Degree Sequence of Graph G
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2454 [别人博客粘贴过来的] 博客地址:https://www.cnblogs.com/debug ...
随机推荐
- BZOJ4974 字符串大师(kmp)
显然最短循环节长度=i-next[i],则相当于给定next数组构造字符串.然后按照kmp的过程模拟即可.虽然这看起来是一个染色问题,但是由图的特殊性,如果next=0只要贪心地选最小的就可以了,稍微 ...
- QT模态对话框及非模态对话框
QT模态对话框及非模态对话框 模态对话框(Modal Dialog)与非模态对话框(Modeless Dialog)的概念不是Qt所独有的,在各种不同的平台下都存在.又有叫法是称为模式对话框,无模式对 ...
- 【刷题】BZOJ 2434 [Noi2011]阿狸的打字机
Description 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机.打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母. 经阿狸研究发现,这个打字机是这样工作的 ...
- 【BZOJ1491】【NOI2007】社交网络(最短路,动态规划)
[BZOJ1491][NOI2007]社交网络(最短路,动态规划) 题面 BZOJ 洛谷 图片是假的,只能到OJ上看 Description 在社交网络(socialnetwork)的研究中,我们常常 ...
- Linux内核设计第一周学习总结 计算机如何工作
北京电子科技学院 20135310陈巧然 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-100002 ...
- 【noip2018】【luogu5021】赛道修建
题目描述 C 城将要举办一系列的赛车比赛.在比赛前,需要在城内修建 mm 条赛道. C 城一共有 nn 个路口,这些路口编号为 1,2,…,n1,2,…,n,有 n-1n−1 条适合于修建赛道的双向通 ...
- 最近公共祖先(LCA)(题目)
Time Limit: 2000 ms Memory Limit: 256 MB Description Input Output Sample Input 15 5 1 2 3 4 5 6 7 8 ...
- 据说要写一个CTSC&APIO的收获
就不写流水帐了,总的写一下吧.先从最浅显的地方开始——知识.大概被普及了一发带花树,算上自己的考试,还被普及了一发洲阁筛.当然更多的还是对于一些知识的强化,比如:乱搞(这东西真是太重点了啊).DP.数 ...
- 2016-2017 ACM-ICPC East Central North America Regional Contest (ECNA 2016) F 区间dp
Problem F Removal GameBobby Roberts is totally bored in his algorithms class, so he’s developed a li ...
- mysql5.7 安装常见问题
mysql 5.7安装要执行以下三个命令: 1.mysql install2.mysqld --initialize3.net start mysql 第一个命令可能会出现Install/Remove ...