UVA 11019 Matrix Matcher
来源:互联网 发布:网络信息安全校园招聘 编辑:程序博客网 时间:2024/06/11 20:20
hash大法好,hash出奇迹。
厉害学弟写厉害的AC自动机,不会,只能拼RP写HASH
。。。
#include<stdio.h>#include<string.h>#include<set>#include<map>#include<algorithm>using namespace std;#define rep(i,s,t) for(int i=s;i<t;i++)typedef unsigned long long ull;const ull B1=10000007;const ull B2=100000007;int t,n,m,x,y,ans;char s[1001][1001],a[101][101];ull p;ull tmp[1001][1001],ttmp[1001][1001];inline ull Hash(){ull c,d=0;rep(i,0,x){c=0;rep(j,0,y){c=c*B1+a[i][j];}d=d*B2+c;}return d;}inline void getAns(){ull t,a;t=1;rep(i,0,y) t*=B1; rep(i,0,n){a=0;rep(j,0,y) a=a*B1+s[i][j];tmp[i][y-1]=a;rep(j,y,m){tmp[i][j]=tmp[i][j-1]*B1-s[i][j-y]*t+s[i][j];}}t=1;rep(i,0,x) t*=B2;rep(i,y-1,m){a=0;rep(j,0,x) a=a*B2+tmp[j][i];ttmp[x-1][i]=a;if(a==p) ans++;rep(j,x,n){ttmp[j][i]=ttmp[j-1][i]*B2-tmp[j-x][i]*t+tmp[j][i];if(ttmp[j][i]==p) ans++;}}}int main(){scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);rep(i,0,n) scanf("%s",s[i]);scanf("%d%d",&x,&y);rep(i,0,x) scanf("%s",a[i]);p=Hash();ans=0;getAns();printf("%d\n",ans);}return 0;}
0 0
- UVA 11019 Matrix Matcher
- Uva 11019 Matrix Matcher
- UVA 11019 Matrix Matcher
- UVA 11019 Matrix Matcher
- UVa 11019 Matrix Matcher
- UVA 11019 Matrix Matcher
- UVA 11019 Matrix Matcher
- UVa:11019 Matrix Matcher(AC自动机)
- Matrix Matcher - UVa 11019 哈希+KMP
- uva 11019 - Matrix Matcher(AC自动机)
- uva 11019 Matrix Matcher 字符串哈希
- UVA 11019 Matrix Matcher(字符hash)
- uva 11019 - Matrix Matcher --AC自动机
- Uva 11019 Matrix Matcher(二维字符串匹配)
- UVA-11019 - Matrix Matcher(AC自动机)
- UVA 11019 Matrix Matcher(AC自动机)
- AC自动机(Matrix Matcher,UVA 11019)
- UVA-11019Matrix Matcher(AC自动机)
- hdu 4494 Teamwork (可行流的最小流)
- Android Notification
- 1.2 连接信号和响应函数
- C2B的未来:大数据定制
- Java内存模型分析
- UVA 11019 Matrix Matcher
- ORACLE TABLE有大量记录,如果增加字段带default值需要很长时间
- 任意进制的大数转换
- 毕业后拉开大家差距的原因
- 1.3 控件的布局排列
- permutation 系列
- poj 3690 Constellations
- OC学习笔记之OC类使用篇
- A nice speech——王强 at 36 Kr