• HDU4513:完美队形II(Manacher)


    Description

     

    Input

     

    Output

     

    Sample Input

     

    Sample Output

     

    Solution

    才发现我之前不会证$Manacher$复杂度……QAQ

    题意是求最长向心非递减回文串。在$Manacher$函数向两边扩展的时候特判一下就好了。

    ┑( ̄Д  ̄)┍复杂度是对的啊……因为$Manacher$的时间复杂度证明和向两边扩的次数有关。

    Code

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #define N (200009)
     5 using namespace std;
     6 
     7 int T,n,x,tot,s[N],len[N];
     8 
     9 void Manacher()
    10 {
    11     int x,ans=0,mid=0,maxn=0;
    12     for (int i=1; i<=tot; ++i)
    13     {
    14         if (i>maxn) x=1;
    15         else x=min(maxn-i+1,len[mid*2-i]);
    16         while (s[i-x]==s[i+x] && s[i-x]<=s[i-x+2]) ++x;
    17         len[i]=x;
    18         if (i+x-1>maxn) maxn=i+x-1, mid=i;
    19         ans=max(ans,x-1);
    20     }
    21     printf("%d
    ",ans);
    22 }
    23 
    24 int main()
    25 {
    26     scanf("%d",&T);
    27     while (T--)
    28     {
    29         scanf("%d",&n);
    30         tot=0; s[++tot]=1e9; s[++tot]=-1;
    31         for (int i=1; i<=n; ++i)
    32             scanf("%d",&x), s[++tot]=x, s[++tot]=-1;
    33         s[++tot]=1e9;
    34         Manacher();
    35     }
    36 }
  • 相关阅读:
    .net 使用 swagger 操作
    oracle 基础
    关于webapi跨域问题的一些坑坑
    sqlHelper
    微博数据接入开发
    mvc后台上传
    sql server 报错处理
    asp.net 微信开发(二)
    收集一些关于OI/ACM的奇怪的东西……
    LeetCode 229 Majority Element II
  • 原文地址:https://www.cnblogs.com/refun/p/10040525.html
Copyright © 2020-2023  润新知