zoukankan      html  css  js  c++  java
  • HDUPattern and Text 枚举

    这题不要去考虑每一个时刻的情况,而要考虑每一个位在所有时间上的叠加效果。

    对于长度为Lf的母串和长度为Ls的子串来说,每个字符匹配的长度都是Lf-Ls+1位。

    代码如下:

    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    using namespace std;
    
    char f[2000005], s[2000005];
    
    int lens, lenf, cnt[30];
    
    int main()
    {
        int T, LIM;
        long long int ans;
        scanf("%d", &T);
        while (T--) {
            ans = 0;
            memset(cnt, 0, sizeof (cnt));
            scanf("%s %s", s, f);
            lenf = strlen(f);
            lens = strlen(s);
            LIM = lenf - lens + 1;
            for (int i = 0;  i < LIM; ++i) {
                ++cnt[f[i]-'a'];
            }
            ans += cnt[s[0]-'a'];
            for (int i = LIM; i < lenf; ++i) {
                --cnt[f[i-LIM]-'a'];
                ++cnt[f[i]-'a'];
                ans += cnt[s[i-LIM+1]-'a'];
            }
            printf("%I64d\n", ans);
        }
        return 0;
    }
  • 相关阅读:
    C#开发规范
    Win32API使用技巧 -- 置顶应用
    Windows开发常用快捷键
    MarkDown简单语法回顾
    样本分布
    复变函数
    set theory
    Oscar的数理统计笔记本
    Oscar的拓扑笔记本
    c语言总结
  • 原文地址:https://www.cnblogs.com/Lyush/p/2617714.html
Copyright © 2011-2022 走看看