题目传送门

 /*
hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举
用set的find函数查找是否存在替换后的字符串,理解后并不难。另外,我想用64位的自然溢出wa了,不清楚
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-5 13:05:49
* File Name :D.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 6e5 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
const int KEY = ;
char s[MAXN];
set<ll> S;
ll ha[MAXN];
int n, m; void init(void) {
ha[] = ;
for (int i=; i<MAXN; ++i) ha[i] = ha[i-] * KEY % MOD;
} ll get_hash(char *s) {
int len = strlen (s);
ll res = ;
for (int i=; i<len; ++i) {
res = (res * KEY + s[i]) % MOD;
}
return res;
} bool judge(char *s) {
int len = strlen (s);
ll h = get_hash (s);
for (int i=; i<len; ++i) {
for (ll ch='a'; ch<='c'; ++ch) {
if (ch == s[i]) continue;
if (S.find ((((ch-s[i]) * ha[len-i-] + h) % MOD + MOD) % MOD) != S.end ()) return true;
}
}
return false;
} int main(void) { //Codeforces Round #291 (Div. 2) C. Watto and Mechanism
init ();
while (scanf ("%d%d", &n, &m) == ) {
S.clear ();
for (int i=; i<=n; ++i) {
scanf ("%s", s);
S.insert (get_hash (s));
}
for (int i=; i<=m; ++i) {
scanf ("%s", s);
if (judge (s)) puts ("YES");
else puts ("NO");
}
} return ;
}

hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism的更多相关文章

  1. 暴力/set Codeforces Round #291 (Div. 2) C. Watto and Mechanism

    题目传送门 /* set的二分查找 如果数据规模小的话可以用O(n^2)的暴力想法 否则就只好一个一个的换(a, b, c),在set容器找相匹配的 */ #include <cstdio> ...

  2. Codeforces Round #291 (Div. 2) C - Watto and Mechanism 字符串

    [题意]给n个字符串组成的集合,然后有m个询问(0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) ,每个询问都给出一个字符串s,问集合中是否存在一个字符串t,使得s和t长度相同,并且仅有一个 ...

  3. Codeforces Round #291 (Div. 2) C. Watto and Mechanism [字典树]

    传送门 C. Watto and Mechanism time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  4. Watto and Mechanism Codeforces Round #291 (Div. 2)

    C. Watto and Mechanism time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  5. 数学 Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun

    题目传送门 /* 水题,就是用三点共线的式子来判断射击次数 */ #include <cstdio> #include <cmath> #include <string& ...

  6. 贪心/字符串处理 Codeforces Round #291 (Div. 2) A. Chewbaсca and Number

    题目传送门 /* WA了好几次,除了第一次不知道string不用'\0'外 都是欠考虑造成的 */ #include <cstdio> #include <cmath> #in ...

  7. Codeforces Round #291 (Div. 2)

    A 题意:给出变换规则,单个数字t可以变成9-t,然后给出一个数,问最小能够变成多少. 自己做的时候理解成了不能输出前导0,但是题目的本意是不能有前导0(即最高位不能是0,其余位数按照规则就好) 55 ...

  8. Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]

    传送门 D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun

    因为是x,y均为整数因此对于同一直线的点,其最简分数x/y是相同的(y可以为0,这里不做除法)于是将这些点不断求最简分数用pair在set中去重即可. #include <cmath> # ...

随机推荐

  1. Spring在Java Filter注入Bean为Null的问题解决

    在Spring的自动注入中普通的POJO类都可以使用@Autowired进行自动注入,但是除了两类:Filter和Servlet无法使用自动注入属性.(因为这两个归Web容器管理)可以用init(集承 ...

  2. cache and database

    This article referenced from http://coolshell.cn/articles/17416.html We all know that high concurren ...

  3. scp、paramiko、rsync复制文件的区别

    1.paramiko只能复制文件,而不能复制目录,复制时,已经存在的会被覆盖;要想复制目录,只能把目录里的文件一个一个复制过去 2.scp可以复制文件.目录,复制时,已经存在的会被覆盖:可以模糊匹配: ...

  4. dstat用法;利用awk求dstat所有列每列的和;linux系统监控

    安装:yum install -y dstat dstat命令是一个用来替换vmstat.iostat.netstat.nfsstat和ifstat这些命令的工具,是一个全能系统信息统计工具.与sys ...

  5. 在ASP.NET Core 中使用Cookie中间件 (.net core 1.x适用)

    在ASP.NET Core 中使用Cookie中间件 ASP.NET Core 提供了Cookie中间件来序列化用户主题到一个加密的Cookie中并且在后来的请求中校验这个Cookie,再现用户并且分 ...

  6. delphi的一些语法知识 以及参数传递问题,按引用方式传递参数,按值方式传递参数

    //delphi中exit,abort,break,continue 的区别 exit: 退出函数体abort: 遇到异常,安静处理,就是不显示不提示break: 退出当前循环体,包括for ,whi ...

  7. Spring MVC的简单使用方法

    一.Multiaction Controller package cn.framelife.mvc.control; import org.springframework.stereotype.Con ...

  8. [Web Analytics] Into to Web Analytics

    Just to get started for myself. Any developer who doesn't care about the business is not a good soft ...

  9. CLLocation的属性以及使用的解释

    http://blog.csdn.net/u012496940/article/details/47405345  上一篇的链接(一个定位实例) 从上一篇中的实例了解所使用的一些元素: CLLcati ...

  10. 【C++ STL应用与实现】18: 怎样使用迭代器适配器

    本系列文章的文件夹在这里:文件夹. 通过文件夹里能够对STL整体有个大概了解 前言 本文介绍了STL中的迭代器适配器(iterator adapter)的概念及其用法演示样例.迭代器适配器能够和标准库 ...