• UVA 11019


    UVA 11019 - Matrix Matcher

    #include <bits/stdc++.h>
    
    using namespace std;
    #define rint register int
    #define rll register long long
    typedef long long ll;
    const int maxn = 1e3 + 100;
    const int base1 = 233, base2 = 2333;
    char a[maxn][maxn], b[maxn][maxn];
    unsigned long long ha[maxn][maxn], hb[maxn][maxn];
    
    
    int main() {
        freopen("in.txt", "r", stdin);
        rint _;
        scanf("%d", &_);
        while (_--) {
            rint n, m, x, y;
            scanf("%d %d", &n, &m);
            for (rint i = 1; i <= n; i++)
                scanf("%s", a[i] + 1);
            scanf("%d %d", &x, &y);
            for (rint i = 1; i <= x; i++)
                scanf("%s", b[i] + 1);
            register unsigned long long p1 = 1, p2 = 1;
            for (rint i = 1; i <= x; i++) {
                p2 *= base2;
            }
            for (rint i = 1; i <= y; i++) {
                p1 *= base1;
            }
            for (rint i = 1; i <= x; i++) {
                for (rint j = 1; j <= y; j++) {
                    hb[i][j] = (b[i][j] - 'a') + hb[i][j - 1] * base1 + hb[i - 1][j] * base2 -
                               hb[i - 1][j - 1] * base1 * base2;
                }
            }
            rint ans = 0;
            for (rint i = 1; i <= n; i++) {
                for (rint j = 1; j <= m; j++) {
                    ha[i][j] = (a[i][j] - 'a') + ha[i][j - 1] * base1 + ha[i - 1][j] * base2 -
                               ha[i - 1][j - 1] * base1 * base2;
                    if (i >= x && j >= y &&
                        hb[x][y] == ha[i][j] - ha[i - x][j] * p2 - ha[i][j - y] * p1 + ha[i - x][j - y] * p1 * p2) {
                        ans++;
                    }
                }
            }
            printf("%d
    ", ans);
        }
    
        return 0;
    }
    
  • 相关阅读:
    递归部门
    web攻击几种方法
    β版本apk下载地址及源代码github地址
    软件工程第六组U-Helpβ版使用说明
    软件工程第六组(六扇门)β版本最终答辩博客
    alpha版本展示
    用户Bug修补报告
    任务墙最终版
    个人总结-尹童欣
    个人总结-齐天浩
  • 原文地址:https://www.cnblogs.com/albert-biu/p/11319358.html
Copyright © 2020-2023  润新知