一个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的更多相关文章

  1. Codefroces 852 G. Bathroom terminal

    G. Bathroom terminal Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to p ...

  2. 【IntellJ IDEA】idea的Terminal窗口中文乱码 解决方法

    在操作git命令在windows上的idea中的terminal窗口时,总是出现中文乱码的问题 本开始以为是git乱码的问题,如果是GIt中文乱码,解决方案:https://www.cnblogs.c ...

  3. 【亲测】<g++/gcc>CentOS下g++: command not found问题的解决(c++环境安装)

    CentOS下g++: command not found问题的解决 2017年02月27日 18:09:06 阅读数:5174 标签: centosgcc 更多 个人分类: 问题分析   版权声明: ...

  4. 【BubbleCup X】D. Exploration plan

    这个题首先一眼能看出二分答案…… 毕竟连可爱的边界都给你了. 下面就是怎么check 首先预处理跑一遍floyed,预处理出最短路. 用网络流判断能否达到即可. #include<bits/st ...

  5. 【ASC 23】G. ACdream 1429 Rectangular Polygon --DP

    题意:有很多棍子,从棍子中选出两个棍子集合,使他们的和相等,求能取得的最多棍子数. 解法:容易看出有一个多阶段决策的过程,对于每个棍子,我们有 可以不选,或是选在第一个集合,或是选在第二个集合 这三种 ...

  6. 【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 ...

  7. 【BubbleCup X】F:Product transformation

    按照题解的规律,首先能看出前面每个数幂次的性质. 然后发掘约数的性质 #include<bits/stdc++.h> ; typedef long long ll; using names ...

  8. 论文阅读笔记:【Transforming Auto-encoders】

    [Transforming Auto-encoders]: G E Hinton, A Krizhevsky, S D Wang. Transforming auto-encoders[C]. //I ...

  9. 【Havel 定理】Degree Sequence of Graph G

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2454 [别人博客粘贴过来的] 博客地址:https://www.cnblogs.com/debug ...

随机推荐

  1. bzoj1007-水平可见直线

    题目 在平面直角坐标系上以\(y=kx+b\)的形式给出\(n (n\le 50000)\)条直线,求从无限高的地方能看到多少条直线. 分析 举几个例子发现我们要求的直线组成一个下凸的形状.所以我们只 ...

  2. 【Java】Java CSV操作代码

    CSV是逗号分隔文件(Comma Separated Values)的首字母英文缩写,是一种用来存储数据的纯文本格式,通常用于电子表格或数据库软件.在 CSV文件中,数据“栏”以逗号分隔,可允许程序通 ...

  3. BZOJ4735 你的生命已如风中残烛 【数学】

    题目链接 BZOJ4735 题解 给定一个序列,有的位置为\(w_i - 1\),有的位置为\(-1\),问有多少种排列,使得任意前缀和非负? 我们末尾加上一个\(-1\),就是要保证除了末尾外的前缀 ...

  4. [POI2008]MAF-Mafia

    Description 有n个人,每个人手里有一把手枪.一开始所有人都选定一个人瞄准(有可能瞄准自己).然后他们按某个顺序开枪,且任意时刻只有一个人开枪.因此,对于不同的开枪顺序,最后死的人也不同. ...

  5. 扶苏的bitset浅谈

    bitset作为C++一个非常好用的STL,在一些题目中巧妙地使用会产生非常不错的效果.今天扶苏来分享一点bitset的基础语法和应用 本文同步发布于个人其他博客,同时作为P3674题解发布. 本文感 ...

  6. jsp中文乱码终极解决方法

    转载http://blog.csdn.net/csh624366188/article/details/6657350 一 找出问题的根源    乱码可能出现的地方:1 jsp页面中          ...

  7. 服务器上的 Git - 在服务器上搭建 Git

    http://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E5%9C%A8%E6%9C%8D%E ...

  8. POJ--2752

    原题链接:http://poj.org/problem?id=2752 分析:no! #include<cstdio> #include<cstring> #include&l ...

  9. bzoj 1528 [POI2005]sam-Toy Cars 堆维护+贪心

    1528: [POI2005]sam-Toy Cars Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 716  Solved: 306[Submit][S ...

  10. 5种网络通信设计模型(也称IO模型)

    1.基本概念 同步:同步函数一般指调用函数后,等到函数功能实现再返回,期间一直霸占的CPU,等待期间同一个线程无法执行其他函数 异步:异步函数指调用函数后,不管函数功能是否实现,立马返回:通过回调函数 ...