Watto and Mechanism CodeForces
来源:互联网 发布:工期优化步骤 编辑:程序博客网 时间:2024/05/22 13:27
题意:
输入n个字符串,然后进行m次询问,每次询问输入一个字符串,问n个字符串中是否存在与当前输入的字符串长度相等,并且刚好有且仅有一个位置的字符不同。存在则输出YES,不存在输出NO。
参考http://blog.csdn.net/u011580493/article/details/43852341
分析:
感觉好坑啊。。
感觉不会hash
- 为什么用ULL会错;
- 为什么是×TS【len-i-1】?
#define ULL long long#define LL long long#define inf 0x3f3f3f3fconst ULL mod=1e9+7;const ULL seed=257;ULL haha[N+2],TS[N+2];char s[N];set<ULL>has;void init(){ TS[0]=1; for(int i=1;i<N;++i){ TS[i]=(TS[i-1]*seed)%mod; }}int gethash(char *s){ int len=strlen(s); ULL tmp=0; for(int i=0;i<len;++i){ tmp=(tmp*seed+s[i])%mod; } return tmp;}bool judge(char *s){ int len=strlen(s); ULL sans=gethash(s); for(int i=0;i<len;++i){ for(char t='a';t<='c';++t){ if(t==s[i])continue; ULL now=(((t-s[i])*TS[len-i-1]+sans)%mod+mod)%mod; if(has.find(now)!=has.end())return true; } } return false;}int main(){ init(); int n,m; sf("%d%d",&n,&m); rep(i,1,n){ sf("%s",s); ULL sans=gethash(s); has.insert(sans); } rep(i,1,m){ sf("%s",s) ; if(judge(s))puts("YES"); else puts("NO"); }}
阅读全文
0 0
- Watto and Mechanism CodeForces
- codeforces 514c Watto and Mechanism (hash)
- codeforces C. Watto and Mechanism 字典树
- CodeForces 514B - Watto and Mechanism
- Codeforces 514C . Watto and Mechanism
- Codeforces 514C Watto And Mechanism 哈希
- C. Watto and Mechanism
- Watto and Mechanism
- Watto and Mechanism - CodeForces 514 C Trie树
- Codeforces Round #291 (Div. 2)---C. Watto and Mechanism
- Codeforces Round #291 (Div. 2) -- C. Watto and Mechanism
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism
- Codeforces 514C - Watto and Mechanism (Trie + DFS)
- codeforces 514C Watto and Mechanism (分段暴力)
- Codeforces 514C Watto and Mechanism Trie树 + dfs
- Codeforces Round #291 (Div. 2) C - Watto and Mechanism
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism
- Codeforces 514C Watto and Mechanism (字典树+dfs)
- 单例类的总结
- Hadoop-No.16之Kafka
- 复习css布局模型
- 宝宝跟随、宠物跟随主人
- JSP基础语法
- Watto and Mechanism CodeForces
- ubuntu16.04和win10安装anaconda以及path配置
- Nodejs-npm包之http-server和json-server
- 《JS高级程序设计》第6章读书笔记:创建对象(一)之工场模式和构造函数模式
- 成为JavaGC专家(2)—如何监控Java垃圾回收机制
- SurfaceView的概念和优点及使用
- 小小粉丝度度熊--尺取法、合并一些重复的区间。
- Android.mk简单分析
- Go指南练习之《斐波纳契闭包》