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> # ...
随机推荐
- PowerDesigner物理模型用法总结
1. 生成sql脚本 Database→Generate Database 选择要输出的文件路径,即文件存储路径,并根据需要修改文件名,单击确定后便会生成sql脚本. 在Options选项卡里,可以 ...
- java中使用Protobuf的实例(Demo)
由于Protobuf受到推崇,故尝试采用protobuf来摒弃传统的xml进行传输数据. 首先,需要下载的关于Protobuf的文件: 1.到http://code.google.com/p/prot ...
- [bzoj1430]小猴打架_prufer序列
小猴打架 bzoj-1430 题目大意:题目链接. 注释:略. 想法: 我们发现打架的情况就是一棵树. 我们只需要把确定树的形态然后乘以$(n-1)!$表示生成这棵树时边的顺序. 一共$n$个节点我们 ...
- 洛谷—— P3386 【模板】二分图匹配
P3386 [模板]二分图匹配(复习) 题目背景 二分图 题目描述 给定一个二分图,结点个数分别为n,m,边数为e,求二分图最大匹配数 输入输出格式 输入格式: 第一行,n,m,e 第二至e+1行,每 ...
- Codeforces Round #414
A =w= B qvq C(贪心) 题意: Alice和Bob分别有长度为n(n<=1e5)的字符串,Alice先手,每次从自己的字符串中抽出一个字母放到新字符串的某个位置,一共轮流n次,也就是 ...
- HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水
简单dp #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- 如何利用神经网络和Python生成指定模式的密码
今天给大家介绍的是Github上一个名叫PyMLProjects的项目,这个项目的目的是为了训练AI来学习人类构造密码的模式,然后我们就可以用AI来生成大量同一模式或种类的密码了.这种方法也许可以用来 ...
- iOS 设备推断 最新统计代码
- (NSString*) deviceName { struct utsname systemInfo; uname(&systemInfo); ...
- java websocket开发的客户端程序
最近用java websocket开发的客户端程序,在和服务端链接通后,在数据传输完毕后,客户端自动关闭了链接,如何能保持链接不断开 这个是客户端的启动类,在循环完毕后,会自动断开和服务器的链接,开始 ...
- TMS320F28335项目开发记录6_28335之cmd文件具体解释
1.CMD文件的作用 CMD文件的作用就像仓库的货物摆放记录一样,为程序代码和数据分配指定的空间. 2.C语言生成的段 C语言生成的段大致分为两大类:初始化和未初始化,已初始化的段含有真正的指令和数据 ...