[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher D HDU 3746
来源:互联网 发布:双程网络剧百度云网盘 编辑:程序博客网 时间:2024/05/16 12:10
题目地址:https://vjudge.net/contest/70325#problem/D
思路:利用NEXT数组求循环节。
AC代码:
#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int maxn=100000+10;int tlen,caset;char t[maxn];int Next[maxn];void getNext(){ int j,k; j=0,k=-1,Next[0]=-1; while(j<tlen) { if(k==-1 || t[j]==t[k]) Next[++j]=++k; else k=Next[k]; }}int main(){ scanf("%d",&caset); while(caset--) { scanf("%s",t); tlen=strlen(t); getNext(); int ans=tlen-Next[tlen]; if(tlen%ans==0 && tlen!=ans) printf("0\n"); else printf("%d\n",ans-Next[tlen]%ans); }}
0 0
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher D HDU 3746
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher A HDU 1711
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher B HDU 1686
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher C HDU 2087
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher E HDU 1358
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher J HDU 2594
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher K HDU 3336
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher J (kmp扩展)
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher K (kmp扩展)
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher L(kmp扩展)
- 【 题集 】 【kuangbin带你飞】专题十六 KMP & 扩展KMP & Manacher
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher F HUST 1010
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher G POJ 2406
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher H POJ 2752
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher I POJ 3080
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher(1) A-H
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher 题目分析
- [kuangbin带你飞]专题十六 KMP & 扩展KMP
- C++ vector
- YII2框架详解
- Java8新特性二--Stream
- RBAC权限控制
- 第十周—C语言 回文数的判定
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher D HDU 3746
- QT - qss(三)QCheckBox和QRadioButton
- java.lang.ArrayIndexOutOfBoundsException ecplise升级jetty版本
- exists 和 select 1 from
- Target runtime Apache Tomcat v8.0 is not defined.
- QT- qss(四)行文本编辑框QLineEdit及自动补全
- BZOJ 3631 松鼠的新家
- 计算个人所得税
- Windows Service 打印文本文档