HDU 3476 Cyclic Nacklace(next数组应用)
来源:互联网 发布:冬瓜影视软件下载 编辑:程序博客网 时间:2024/06/16 20:22
http://acm.hdu.edu.cn/showproblem.php?pid=3746
题目大意:
给你一个串 问添至少加多少个字符使这个串变成循环的
分析:
next数组的简单应用 求出next数组后 如果next[len-1]==-1 要添加字符就是整个串 然后求一下循环节就好了 看一下是不是多次循环的
AC代码:
#include <iostream>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>#include <vector>#include <stack>#include <queue>#include <map>#include <set>#include<list>#include <bitset>#include <climits>#include <algorithm>#define gcd(a,b) __gcd(a,b)#define mset(a,n) memset(a,n,sizeof(a))#define FINfreopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w",stdout)typedef long long LL;const LL mod=1e9+7;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);using namespace std;int Next[1000010];char str[1000010];void get_Next(char *str,int &n){ n=strlen(str); int j=-1; Next[0]=-1; for (int i=1;i<n;i++){ while (j>=0&&str[i]!=str[j+1]) j=Next[j]; if (str[i]==str[j+1]) j++; Next[i]=j; }}int main (){int t;scanf ("%d",&t); while (t--){ int len; scanf("%s",str); get_Next(str,len); int length=len-(Next[len-1]+1);// 求出循环节长度 if (Next[len-1]==-1) printf ("%d\n",len); else if (len%length==0) printf ("0\n");// 循环多次 else printf ("%d\n",length-len%length);// 要添加的字符个数使其循环多次 } return 0;}
阅读全文
0 0
- HDU 3476 Cyclic Nacklace(next数组应用)
- Cyclic Nacklace next数组应用
- HDU 3746 Cyclic Nacklace (next数组的应用)
- HDU Cyclic Nacklace (KMP-next数组的利用)
- HDU 3746 Cyclic Nacklace(Next 数组性质)
- HDU-3746 Cyclic Nacklace (活用KMP中next数组)
- HDU 3746 Cyclic Nacklace (next数组)
- Cyclic Nacklace (kmp next数组的应用)
- HDU 3746 Cyclic Nacklace //深刻理解next数组
- hdu 3749 Cyclic Nacklace(kmp next数组获取循环节)
- hdu 3746 Cyclic Nacklace(KMP中next数组的运用)
- Cyclic Nacklace (kmp中next数组的运用)
- HDU-3746 Cyclic Nacklace (对next的深入思考)
- Cyclic Nacklace(HDU 3746)
- HDU 3746 Cyclic Nacklace 利用 KMP的next数组求循环节
- HDU--杭电--3746--Cyclic Nacklace--KMP--next值的应用
- hdu 3746 Cyclic Nacklace(KMP)
- hdu 3746 Cyclic Nacklace(KMP)
- Centos7.0开发环境配置
- 面向对象学习(二)—原型
- leetcode之链表类之链表排序-----147/148. 链表快速排序 链表插入排序
- 十个利用矩阵乘法解决的经典题目
- 86. Partition List
- HDU 3476 Cyclic Nacklace(next数组应用)
- 数据结构之 将顺序表所有元素逆置,要求空间复杂度为O(1)
- Android SELinux Enforcing 模式下问题及解决
- Qt获取本地IP
- Cannot proceed because system tables used by Event Scheduler where found damaged at server start
- Intellij Idea安装主题包
- linux的scp命令
- Hello World in Tensorflow on Jupyter via Anaconda:
- maven下搭建springMVC+mybatis+mysql+zookeeper+dubbo