zoukankan      html  css  js  c++  java
  • HDU-4763

    传送门

    T组字符串 问每个字符串中是否能找到一个子串在原串中互不重叠地出现三次(或以上),且该子串是原串的前缀、后缀。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    typedef long long LL;
    
    const int maxn = 1e6 + 10;
    char s[maxn];
    int f[maxn];
    int len;
    int T;
    bool vis[maxn];
    
    void getFail(char* P, int* f) {
        f[0] = 0; f[1] = 0;
        for (int i = 1; i < len; i++) {
            int j = f[i];
            while (j && P[i] != P[j]) j = f[j];
            f[i + 1] = P[i] == P[j] ? j + 1 : 0;
        }
    }
    
    int main() {
        scanf("%d", &T);
        while (T--) {
            scanf("%s", s);
            len = strlen(s);
            getFail(s, f);
            int t = len;
            int ans = 0;
            memset(vis, 0, sizeof(vis));
            while (t) {
                t = f[t];
                vis[t] = 1;
            }
            for (int i = len; i ; i--) {
                int t = i;
                while (t) {
                    if (vis[f[t]] && t >= 2 * f[t] && len - t >= f[t]) {
                        ans = max(ans, f[t]);
                    }
                    t = f[t];
                }
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    系统运维易忘点总结之七
    SqlServer的排序规则
    Oracle数据库用户密码过期解决
    linux 查看即时网速 /流量的工具
    NFS部署过程
    NFS 共享存储
    Rsync服务的实战
    ncRsync服务
    架构名词
    状态码
  • 原文地址:https://www.cnblogs.com/xFANx/p/8510900.html
Copyright © 2011-2022 走看看