• 【bzoj2462】[BeiJing2011]矩阵模板


    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    using namespace std;
     
    #define MAXN 100000000
    #define prime1 9983543
    #define prime2 9804799
    #define MOD 99999971
    #define N 1010
     
    int m,n,A,B,q;
     
    unsigned int hash;
     
    unsigned int a[N][N],b[N][N],p1[N],p2[N];
    bool h[MAXN];
     
    int main()
    {
        scanf("%d%d%d%d",&m,&n,&A,&B);
        for (int i=1;i<=m;i++)
            for (int j=1;j<=n;j++)
                scanf("%1d",&a[i][j]);
        for (int i=1;i<=m;i++)
            for (int j=1;j<=n;j++)
                a[i][j]+=a[i-1][j]*prime1;
        for (int i=1;i<=m;i++)
            for (int j=1;j<=n;j++)
                a[i][j]+=a[i][j-1]*prime2;
        p1[0]=1;
        p2[0]=1;
        for (int i=1;i<=min(m,n);i++)
            p1[i]=p1[i-1]*prime1,p2[i]=p2[i-1]*prime2;
        for (int i=A;i<=m;i++)
            for (int j=B;j<=n;j++)
            {
                hash=a[i][j];
                hash-=a[i-A][j]*p1[A];
                hash-=a[i][j-B]*p2[B];
                hash+=a[i-A][j-B]*p1[A]*p2[B];
                hash%=MOD;
                h[hash]=1;
            }
        scanf("%d",&q);
        while (q--)
        {
            for (int i=1;i<=A;i++)
                for (int j=1;j<=B;j++)
                    scanf("%1d",&b[i][j]);
            for (int i=1;i<=A;i++)
                for (int j=1;j<=B;j++)
                    b[i][j]+=b[i-1][j]*prime1;
            for (int i=1;i<=A;i++)
                for (int j=1;j<=B;j++)
                    b[i][j]+=b[i][j-1]*prime2;
            puts(h[b[A][B]%MOD] ? "1" : "0");
        }
        return 0;
    }
  • 相关阅读:
    以结构体为键值的map
    Luogu P1251 餐巾计划问题 (最小费用最大流、拆点)
    CodeForces
    CodeForces
    中缀表达式转后转表达式
    CodeForces
    Educational Codeforces Round 100
    2020年12月杂题选做
    2020年11月杂题选做
    CF542E Playing on Graph
  • 原文地址:https://www.cnblogs.com/yangjiyuan/p/5699402.html
Copyright © 2020-2023  润新知