题目传送门

 1 /*
 2     hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举
 3         用set的find函数查找是否存在替换后的字符串,理解后并不难。另外,我想用64位的自然溢出wa了,不清楚
 4 */
 5 /************************************************
 6 * Author        :Running_Time
 7 * Created Time  :2015-8-5 13:05:49
 8 * File Name     :D.cpp
 9  ************************************************/
10
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 6e5 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36 const int KEY = 257;
37 char s[MAXN];
38 set<ll> S;
39 ll ha[MAXN];
40 int n, m;
41
42 void init(void) {
43     ha[0] = 1;
44     for (int i=1; i<MAXN; ++i)  ha[i] = ha[i-1] * KEY % MOD;
45 }
46
47 ll get_hash(char *s)    {
48     int len = strlen (s);
49     ll res = 0;
50     for (int i=0; i<len; ++i)  {
51         res = (res * KEY + s[i]) % MOD;
52     }
53     return res;
54 }
55
56 bool judge(char *s) {
57     int len = strlen (s);
58     ll h = get_hash (s);
59     for (int i=0; i<len; ++i)   {
60         for (ll ch='a'; ch<='c'; ++ch)    {
61             if (ch == s[i])   continue;
62             if (S.find ((((ch-s[i]) * ha[len-i-1] + h) % MOD + MOD) % MOD) != S.end ())    return true;
63         }
64     }
65     return false;
66 }
67
68 int main(void)    {     //Codeforces Round #291 (Div. 2) C. Watto and Mechanism
69     init ();
70     while (scanf ("%d%d", &n, &m) == 2) {
71         S.clear ();
72         for (int i=1; i<=n; ++i)    {
73             scanf ("%s", s);
74             S.insert (get_hash (s));
75         }
76         for (int i=1; i<=m; ++i)    {
77             scanf ("%s", s);
78             if (judge (s))  puts ("YES");
79             else    puts ("NO");
80         }
81     }
82
83     return 0;
84 }

转载于:https://www.cnblogs.com/Running-Time/p/4705101.html

hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism相关推荐

  1. CodeForces Round #291 Div.2

    A. Chewbaсca and Number 感觉这道题巨坑,如果题中加粗标出来的输出得是正数算小坑的话.有个巨坑就是 the final number shouldn't start with a ...

  2. Codeforces Round #291 (Div. 2)

    A 简单题 B 简单题 C 求改变一个字母的单词是否出现过 字典树+dfs D k次射击 每次可以把一列都减小1 总共m列 m列都为0就被破坏掉 问最多连续多少个被破坏掉 二分答案 在用数据结构询问某 ...

  3. Codeforces Round #400 (Div. 1 + Div. 2, combined) 776E. The Holmes Children(待翻译)

    Codeforces Round #241 (Div. 2) 514C Watto and Mechanism ≤,≠,≥<> 时间限制:1S / 空间限制:256MB [在线测试提交传送 ...

  4. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

  5. Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #694 (Div. 1 + Div2)(A ~ ...

  6. Codeforces Round FF(Div. 2)

    layout: post title: Codeforces Round FF(Div. 2) author: "luowentaoaa" catalog: true tags: ...

  7. 10.1 Codeforces Round #590 (Div.3)

    Codeforces Round #590 (Div. 3):点击进入新世界 总结: 第二次实时打cf,刚开始四分钟就且切了A题,后面看了B1 B2 难度改变对思路没有影响,一开始思路是对的,但是用h ...

  8. Codeforces Round #783 (Div. 2)和Codeforces Round #784 (Div. 4)---- ABC | ABCDEF

    目录 Codeforces Round #783 (Div. 2) A B C Codeforces Round #784 (Div. 4) A B C D E F Codeforces Round ...

  9. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

最新文章

  1. 从MATLAB帮助文档上学习 chirp
  2. Swift实战-QQ在线音乐(第二版)
  3. android点击输入法会把底部顶上去的解决办法
  4. Java 平台调试架构JPDA
  5. 数据结构与算法2——数组
  6. 蒙特卡洛模拟预测股票_使用蒙特卡洛模拟来预测极端天气事件
  7. MindSpore小笔记
  8. 物联网安全白皮书_天翼物联网安全白皮书发布 有方科技参与编纂
  9. java 后台线程作用_Java 后台线程介绍
  10. C语言open()函数:打开文件函数(转)
  11. 第二周作业购物车程序
  12. 【渝粤题库】广东开放大学 组织行为学 形成性考核
  13. 线性表——链表(含代码)
  14. Django分页+增删改查
  15. leetcode报错:member access within null pointer of type struct ListNode
  16. ArcGIS地理数据处理高级教程_002_2初识地理处理工具
  17. Scratch软件编程等级考试一级——20211211
  18. windows bitlocker 控制台加密、解密脚本
  19. 网络游戏开发之安全对抗
  20. SF21 | 利用PSY指标,我们来开发一个短线模型?

热门文章

  1. nginx 反向代理跨域访问配置_nginx反向代理配置去除前缀
  2. c++代码小游戏_用Python编写一个打乒乓球小游戏
  3. 双目视觉——SGM中的动态规划
  4. Hough直线检测的理解
  5. UpdateLayeredWindow 绘制异型窗口
  6. SpringIOCAOP
  7. mybatis-generator自动生成mapper
  8. hadoop集群环境搭建
  9. 100. Same Tree同样的树
  10. Jumping Jack