一个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. 对Spark2.2.0文档的学习3-Spark Programming Guide

    Spark Programming Guide Link:http://spark.apache.org/docs/2.2.0/rdd-programming-guide.html 每个Spark A ...

  2. 【codevs1163】访问艺术馆 树形dp

    题目描述 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结构,每条走廊要么分叉为二条走廊,要么通向一个展览室.皮尔知道每个展室里藏画的数量,并且他精确地测量了通过每条走廊的 ...

  3. Contest 6

    A:容易发现这要求所有子集中元素的最高位1的位置相同,并且满足这个条件也是一定合法的.统计一下即可. #include<iostream> #include<cstdio> # ...

  4. 转:pairwise 代码参考

    Learning to rank with scikit-learn: the pairwise transform http://fa.bianp.net/blog/2012/learning-to ...

  5. 创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或

    C:\Users\xxx\Documents\IISExpress\config\applicationhost.config 将这里面带的项目路径替换成你当前路径 {"创建 caching ...

  6. 【刷题】BZOJ 2142 礼物

    Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同,在小E心中分量越重的人,收到的礼物会越多.小E从商店 ...

  7. Sort Integers II

    Given an integer array, sort it in ascending order. Use quick sort, merge sort, heap sort or any O(n ...

  8. crontab 自动执行脚本

    crontab -e ================>自动执行某脚本!!!!!!! 1001 ls 1002 cd /home/wwwroot/default/ 1003 ls 1004 cr ...

  9. 贪心法:K叉哈夫曼树

    NOI2015荷马史诗 一部<荷马史诗>中有 n 种不同的单词,从 1 到 n 进行编号.其中第 i 种单词出现的总次数为 wi.Allison 想要用 k 进制串 si 来替换第 i 种 ...

  10. [洛谷P2750] [USACO5.5]贰五语言Two Five

    洛谷题目链接:[USACO5.5]贰五语言Two Five 题目描述 有一种奇怪的语言叫做"贰五语言".它的每个单词都由A-Y这25个字母各一个组成.但是,并不是任何一种排列都是一 ...