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> # ...
随机推荐
- [SCOI2008]奖励关 - 状压动规 - 概率与期望
Description 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝 ...
- csu - 1536: Bit String Reordering (模拟)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1536 不知道为何怎么写都写不对. 这题可以模拟. 虽然题目保证一定可以从原串变成目标串,但是不一定 ...
- HDU - 2059 龟兔赛跑(多阶段决策dp)
http://acm.hdu.edu.cn/showproblem.php?pid=2059 初始把起点和终点也算做充电站,设dp[i]是到第i个充电站的最短时间,那么dp[n+1]即是乌龟到达终点的 ...
- [bzoj2506]calc_分块处理
calc bzoj-2506 题目大意:给一个长度为n的非负整数序列A1,A2,…,An.现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且Ai mod p = k的值i的个 ...
- Linux下tomcat的catalina.out屏蔽
修改catalina.sh ,找到下面的位置: if [ -z "$CATALINA_OUT" ] ; then#CATALINA_OUT="$CATALINA_BASE ...
- Spring Boot-Logback 配置(区分环境、分包、分级别打印)
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!--生产环境 - ...
- Why we have tuple and list in python
The most notable difference between tuple and list is that tuple is immutable and list is mutable. B ...
- 上下文( Contexts )
在 Indy9 的服务器中,链接特定(connection specific)的数据被作为线程类的一部分被存储. 实现这个要不然通过使用 thread.data 属性要不然通过继承对应的 thread ...
- UVa 1531 - Problem Bee
题目:如图所看到的的蜂巢型的图中.蜜蜂想从A点飞到B点,假设A与B不在同一个正六边形中, 则它先飞到A的中心.每次飞到相邻格子的中心,最后飞到B的中心,再飞到B点: 假设在一个格子中.直接飞过去就可以 ...
- Objective-C之成魔之路【8-訪问成员变量和属性】
郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 訪问成员变 ...