hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism
/*
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的更多相关文章
- 暴力/set Codeforces Round #291 (Div. 2) C. Watto and Mechanism
题目传送门 /* set的二分查找 如果数据规模小的话可以用O(n^2)的暴力想法 否则就只好一个一个的换(a, b, c),在set容器找相匹配的 */ #include <cstdio> ...
- Codeforces Round #291 (Div. 2) C - Watto and Mechanism 字符串
[题意]给n个字符串组成的集合,然后有m个询问(0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) ,每个询问都给出一个字符串s,问集合中是否存在一个字符串t,使得s和t长度相同,并且仅有一个 ...
- 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 ...
- 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 ...
- 数学 Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun
题目传送门 /* 水题,就是用三点共线的式子来判断射击次数 */ #include <cstdio> #include <cmath> #include <string& ...
- 贪心/字符串处理 Codeforces Round #291 (Div. 2) A. Chewbaсca and Number
题目传送门 /* WA了好几次,除了第一次不知道string不用'\0'外 都是欠考虑造成的 */ #include <cstdio> #include <cmath> #in ...
- Codeforces Round #291 (Div. 2)
A 题意:给出变换规则,单个数字t可以变成9-t,然后给出一个数,问最小能够变成多少. 自己做的时候理解成了不能输出前导0,但是题目的本意是不能有前导0(即最高位不能是0,其余位数按照规则就好) 55 ...
- 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 ...
- Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun
因为是x,y均为整数因此对于同一直线的点,其最简分数x/y是相同的(y可以为0,这里不做除法)于是将这些点不断求最简分数用pair在set中去重即可. #include <cmath> # ...
随机推荐
- android view自定义
转载自:http://blog.csdn.net/iispring/article/details/50708044
- Python基础之 一列表
列表模块:listlen(list):列表元素个数max(list):列表元素最大值min(list):列表元素最小值list(seq):将元组转为列表list.append(obj):列表末尾添加新 ...
- Educational Codeforces Round 41 B、C、D
http://codeforces.com/contest/961 B题 可以将长度为k的连续区间转化成1 求最大和 解析 简单尺取 #include <stdio.h> #include ...
- IE11 文档模式空白
环境描述: win7 64位系统 安装了 更新 IE11-Windows6.1-KB2929437-x64.IE11-Windows6.1-KB3008923-x64 解决方案: 卸载 IE11-Wi ...
- poj3511--A Simple Problem with Integers(线段树求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 60441 ...
- xib或者storyboard设置颜色偏问题(与代码设置颜色不一致)
选中xib中的label,在右边栏的第三个标签页中第三项是User Defined Runtime Attributes 添加一个keyPath,keyPath值为layer.borderWidth, ...
- linux句柄泄露问题查看
背景: 我们在开发linux在线server的时候常常会遇会句柄泄露的问题.由于在linux系统设计里面遵循一切都是文件的原则.即磁盘文件.文件夹.网络套接字.磁盘.管道等,全部这些都是文件.在我们进 ...
- Java小白手记:WEB项目等
机缘巧合之下,工作中得以用一下java.我向来对java很感兴趣,想从.NET转到java久矣,机会难得,久旱逢甘霖. 这次主要是跟web项目有关.在此之前,我了解到JAVA分为三大块:j2se.j2 ...
- cojs 1001. [WZOI2011 S3] 消息传递
1001. [WZOI2011 S3] 消息传递 ★★ 输入文件:messagew.in 输出文件:messagew.out 简单对比时间限制:1 s 内存限制:128 MB Prob ...
- 【bzoj1507】[NOI2003]Editor
第二次写rope了 rope大法好!!! #include<algorithm> #include<iostream> #include<ext/rope> #in ...