一个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. BZOJ 1222 产品加工(DP)

    某加工厂有A.B两台机器,来加工的产品可以由其中任何一台机器完成,或者两台机器共同完成.由于受到机器性能和产品特性的限制,不同的机器加工同一产品所需的时间会不同,若同时由两台机器共同进行加工,所完成任 ...

  2. Git Gerrit Repo User Manual

                      Git Repo Gerrit User Manual Revision History   Revision # Description Date Author ...

  3. Eclipse中使用git提交代码,报错Testng 运行Cannot find class in classpath的解决方案

    一.查找原因方式 1.点击Project——>Clear...——>Build Automatically 2.查看问题 二.报错因素 1.提交.xlsx文件 2.提交时,.xlsx文件被 ...

  4. Notepad++查找和替换空行/空格/换行

    Notepad++查找和替换支持正则表达式,功能很强大,但比较复杂因此暂不研究 Notepad++使用正则表达式查找,首先需要勾选查找/替换窗口左下部的“正则表达式(E)”\r\n表示换行,其中\r表 ...

  5. URL补充

    1. 笔记 2. 关于默认值的解释:在url里面,可以直接给views.index传递一个默认值. index函数接收一个形式参数. 在urls.py中,可以直接传递一个实参(也就是默认值). 打印结 ...

  6. Mybatis笔记一:java.lang.NoClassDefFoundError: org/apache/ibatis/mapping/DatabaseIdProvider

    异常错误:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSess ...

  7. 【BZOJ2437】【NOI2011】兔兔与蛋蛋(博弈论,二分图匹配)

    [BZOJ2437][NOI2011]兔兔与蛋蛋(博弈论,二分图匹配) 题面 BZOJ 题解 考虑一下暴力吧. 对于每个状态,无非就是要考虑它是否是必胜状态 这个直接用\(dfs\)爆搜即可. 这样子 ...

  8. 【BZOJ3894】文理分科(最小割)

    [BZOJ3894]文理分科(最小割) 题面 BZOJ Description 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠 结过) 小P所在的班级要进行文理分科.他的班级可以用一个 ...

  9. profit

    Portal --> broken qwq Description 大M成立的怪兽电力公司最近刚建立了一个网站.这个季度共有\(n\)天,第\(i\)天共有\(v[i]\)个用户点击该网站,总的 ...

  10. STL源码分析-traits

    http://note.youdao.com/noteshare?id=b5fd9f936cd133af3790a8b0e9c35b8a