bzoj2462: [BeiJing2011]矩阵模板

咕咕咕

 

这题数据有点水...我直接求矩阵和,比较矩阵大小...还a了

矩阵hash棵题

 

唉...懒得写正解了...既然假的都过了

//bzoj 2462
//二维hash
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
inline int read()
{
    int sum = 0,p = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')
            p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        (sum *= 10) += ch - '0';
        ch = getchar();
    }
    return sum * p;
}
const int N = 1009;
int n,m,na,mb,cnt,p[N][N],a[N][N],b[N][N];
bool flag;
int main()
{
    n = read(),m = read(),na = read(),mb = read();
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            scanf("%1d",&a[i][j]);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            p[i][j] = p[i][j - 1] +p[i - 1][j] - p[i - 1][j - 1] + a[i][j];
    int q = read();
    for(int i = 1;i <= q;i++)
    {
        flag = false;
        cnt = 0;
        for(int i = 1;i <= na;i++)
            for(int j = 1;j <= mb;j++)
            {
                scanf("%1d",&b[i][j]);
                cnt += b[i][j];
            }
        for(int i = na;i <= n;i++)
            for(int j = mb;j <= m;j++)
                if(cnt == p[i][j] - p[i][j - mb] - p[i - na][j] + p[i - na][j - mb])
                {
                    printf("1\n");
                    flag = true;
                    i = n + 1;
                    j = m + 1;
                }
        if(!flag)
            printf("0\n");
    }
    return 0;
}
假的正解

 

posted @ 2019-08-09 09:37  darrrr  阅读(...)  评论(...编辑  收藏