【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 ...
随机推荐
- 【数据库_Postgresql】数据库主键自增长之加序列和不加序列2种方法
将表的主键进行序列增加之后可以在数据库层面自动主键id增长 方法如下:先建序列,然后建表关联id主键,然后添加语句,不用考虑id主键 DROP SEQUENCE IF EXISTS "pub ...
- Contest 3
A:非常裸的dp. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstrin ...
- Unity3D for VR 学习(9): Unity Shader 光照模型 (illumination model)
关于光照模型 所谓模型,一般是由学术算法发起, 经过大量实际数据验证而成的可靠公式 现在还记得2009年做TD-SCDMA移动通信算法的时候,曾经看过自由空间传播模型(Free space propa ...
- php 阿拉伯数字转中文
function numToWord($num){$chiNum = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');$chiUni = ...
- openssl生成https证书、转换证书格式的各种相关操作
第一步:生成 private key.csr等文件 我们可能需要输入以下信息(交互式): --- Country Name (2 letter code) [AU]:US State or Provi ...
- mongodb replica set 和 nodejs中使用mongoose连接replica
一.mongodb replication 介绍 官网上的第一句话就是Replication is the process of synchronizing data across multiple ...
- python 深、浅拷贝
Python的数据结构总体分为两类: 1.字符串和数字 2.列表.元组.字典等 一.字符串和数字 对于字符串和数字而言,赋值(=).浅拷贝(copy)和深拷贝(deepcopy)其实都没有意义,因为它 ...
- mysql cpu 占用高
vi /etc/my.cnf [mysqld]tmp_table_size=200M mysql> show global status like ‘created_tmp%‘; +—————— ...
- C++ string类析构报错
我项目中用到了字符串的Base64转码.DES解密等功能,可能DES解密算法只能解密8字节倍数长度的字符串,所以我得到的结果总会存在一个多余的“尾巴”,于是我想要做一个字符串尾部清理的工作.我的做法是 ...
- Ant Design Upload 组件上传文件到云服务器 - 七牛云、腾讯云和阿里云的分别实现
在前端项目中经常遇到上传文件的需求,ant design 作为 react 的前端框架,提供的 upload 组件为上传文件提供了很大的方便,官方提供的各种形式的上传基本上可以覆盖大多数的场景,但是对 ...