POJ 3461 Oulipo hash求匹配
来源:互联网 发布:微动力cms 编辑:程序博客网 时间:2024/06/15 23:48
题目:
http://poj.org/problem?id=3461
题意:
给一个模式串,一个原串,问原串中有多少个模式串
思路:
kmp模板题,这里用hash算法
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;typedef unsigned long long ull;const int N = 1000000 + 10, M = 10000 + 10, INF = 0x3f3f3f3f;const int seed = 31;//31,131,1313,13131,131313...char pat[M], ori[N];ull Seed[N], hash_ori[N];ull BKDRhash(char *str){ ull h = 0; for(int i = 0; str[i]; i++) h = h * seed + str[i]; return h;}int main(){ Seed[0] = 1; for(int i = 1; i < N; i++) Seed[i] = Seed[i-1] * seed; int t; scanf("%d", &t); while(t--) { scanf("%s%s", pat+1, ori+1); ull hash_pat = BKDRhash(pat+1); int len_pat = strlen(pat+1); hash_ori[0] = 0; int ans = 0; for(int i = 1; ori[i]; i++) { hash_ori[i] = hash_ori[i-1] * seed + ori[i];//也是BKDRhash int j = i - len_pat + 1; if(j >= 1) { if(hash_ori[i] - hash_ori[j-1]*Seed[len_pat] == hash_pat) ans++; } } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- POJ 3461 Oulipo hash求匹配
- POJ 3461 Oulipo(KMP求匹配次数)
- poj 3461 Oulipo (KMP||hash)
- 【poj 3461】Oulipo hash求子串hash值
- poj 3461 Oulipo (求匹配字符串的个数)(KMP)
- poj 3461 Oulipo(KMP 字符串匹配算法)
- POJ 3461 Oulipo(KMP字符串匹配)
- poj 3461 Oulipo kmp字符串匹配
- poj 3461 Oulipo 字符串匹配 KMP算法
- KMP 字符串匹配 POJ 3461 Oulipo
- POJ 3461 Oulipo(KMP匹配)
- POJ 2406 Power Strings hash求匹配
- POJ 3461 Oulipo(自己YY的模式匹配算法)
- 字符串匹配之KMP算法(POJ 3461 Oulipo)
- Oulipo poj 3461 KMP连续匹配(有重合)
- (串的模式匹配4.6.2)POJ 3461 Oulipo(KMP算法的应用——求一个单词在一行文本中的出现次数)
- POJ 3461 Oulipo
- POJ-3461 Oulipo
- Oculus开通VR体验设计博客,为VR开发者分享经验教训
- DiskFileItemFactory的两个方法 .setSizeThreshold和.setRepository
- LitePal使用
- 【python 数据可视化 】饼图,箱线图,条形图,直方图,折线图,散点图
- MYISAM表损坏 通过mysqlcheck进行表修复
- POJ 3461 Oulipo hash求匹配
- 7.5 Django Book ---未完待续
- Android仿QQ侧滑菜单
- FastDFS学习笔记 -- day03 上传图片测试
- 生活告诉我选择正确的路可以走的更长远
- OpenFlow协议-整体结构和协议篇
- WebView加载assets文件乱码
- Hashset,Hashtable,Hashmap总结
- 分页查询