HDU 4763 Theme Section
题目:
To get well prepared for the festival, the hosts want to know the maximum possible length of the theme section of each song. Can you help us?
Input
The integer N in the first line denotes the total number of songs in the festival. Each of the following N lines consists of one string, indicating the notes of the i-th (1 <= i <= N) song. The length of the string will not exceed 10^6.
Output
There will be N lines in the output, where the i-th line denotes the maximum possible length of the theme section of the i-th song.
Sample Input
5
xy
abc
aaa
aaaaba
aaxoaaaaa
Sample Output
0
0
1
1
2
题意描述:
题目很有意思,输入一个字符串
计算并输出该串中“主题章节”的长度
解题思路:
属于KMP的next[]数组的应用。数据很水,放心提交。
代码实现:
/*
判断一个字符是否满足EAEBE,其中E为相同,满足输出最大的E的长度
找到EAEBE的相似度t=next[l],在找AEB中是否存在一个相似度为t,如果存在且t不等于0输出t,否则存在特殊情况
比如a
aa
aaa
结果均是l/3
*/
#include<stdio.h>
#include<string.h>
char s[];
int next[],l;
int get_next(char t[]);
int main()
{
int n,t,flag,i;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
l=strlen(s);
get_next(s);
t=next[l];
for(flag=,i=t;i<=l-t;i++)
{
if(next[i]==t)
flag=;
}
if(!flag || !t)
{
if(t+==l)
printf("%d\n",l/);
else
printf("0\n");
}
else
printf("%d\n",t);
}
return ;
}
int get_next(char t[])
{
int i,j;
i=;j=-;
next[]=-;
while(i < l)
{
if(j==- || t[i]==t[j])
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
/*for(i=0;i<=l;i++)
printf("%d ",next[i]);
printf("\n");*/
}
HDU 4763 Theme Section的更多相关文章
- hdu 4763 Theme Section(KMP水题)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 4763 Theme Section(KMP灵活应用)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 4763 Theme Section (2013长春网络赛1005,KMP)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 2013长春网赛1005 hdu 4763 Theme Section(kmp应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题意:给出一个字符串,问能不能在该串的前中后部找到相同的子串,输出最长的字串的长度. 分析:km ...
- HDU 4763 Theme Section(KMP+枚举公共前后缀)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目大意: 给你一个字符串s,存在一个子串E同时出现在前缀.中间.后缀,即EAEBE这种模式,A ...
- CF126B password&&HDU 4763 Theme Section
http://acm.hdu.edu.cn/showproblem.php?pid=4763 http://codeforces.com/problemset/problem/126/B 这两个题都是 ...
- HDU 4763 Theme Section ( KMP next函数应用 )
设串为str, 串长为len. 对整个串求一遍next函数,从串结尾开始顺着next函数往前找<=len/3的最长串,假设串长为ans,由于next的性质,所以找到的串肯定满足E……E这种形式, ...
- HDU - 4763 Theme Section (KMP的next数组的应用)
给定一个字符串,求出一个前缀A,使得字符串的构成可以表示成ABABA的形式(B可以为空串). 输出这个前缀的最大长度. KMP算法Next数组的使用. 枚举中间的每个位置,可以根据Next数组求出这个 ...
- hdu 4763 Theme Section(next数组找串中三段相等)
题意:在一个串中找 EAEBE 的形式的最长的E,其中E为一个字符串,也就是说找到前缀与后缀相同,并且串中还存在相同的一段,它们不能重复. 思路:利用next数组,next[len]代表的即是最大的相 ...
随机推荐
- c#发展前景
根据育龙网资料评价显示:C#几乎集中了所有关于软件开发和软件工程研究的最新成果:面向对象.类型安全.组件技术.自动内存管理.跨平台异常处理.版本控制.代码安全管理…….尽管像很多人注意到的一样,罗列上 ...
- js控制图片自动缩放,实现铺满盒子,不变形,完全局中
此js一般用于控制图片铺满盒子,但是比例不变,并且绝对局中原理:判断图片的高宽与盒子高宽的大小的关系,然后通过比例来控制图片的缩放及定位<!DOCTYPE html PUBLIC "- ...
- Go基础之--结构体和方法
结构体的定义 结构体是将零个或者多个任意类型的命令变量组合在一起的聚合数据类型.每个变量都叫做结构体的成员. 其实简单理解,Go语言的结构体struct和其他语言的类class有相等的地位,但是GO语 ...
- MicroPython之TPYBoard v102开发板控制OLED显示中文
转载请以链接形式注明文章来源,公众号:MicroPython玩家汇 0x00前言 之前看到一篇文章是关于TPYBoardv102控制OLED屏显示的,看到之后就想尝试一下使用OLED屏来显示中文.最近 ...
- Spark入门,概述,部署,以及学习(Spark是一种快速、通用、可扩展的大数据分析引擎)
1:Spark的官方网址:http://spark.apache.org/ Spark生态系统已经发展成为一个包含多个子项目的集合,其中包含SparkSQL.Spark Streaming.Graph ...
- left join,right join,inner join
数据库中left join,right join,inner join的差异 具体详细说明 总的来说: JOIN: ...
- java socket 和.net socket 通讯 demo
结束符协议"##" import java.io.BufferedReader; import java.io.IOException; import java.io.InputS ...
- 【知了堂学习心得】浅谈c3p0连接池和dbutils工具类的使用
1. C3P0概述 C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展.目前使用它的开源项目有Hibernate,Spring等. 2. C3P ...
- 解决mariadb grant ERROR 1045 (28000): Access denied for user
下面我们一起来看一篇解决mariadb grant ERROR 1045 (28000): Access denied for user问题,希望文章能够帮助到各位朋友. 用mariadb也有一段 ...
- js 数组的常用方法
pop,push,reverse,shift,sort,splice,unshift 会改变原数组 join,concat,indexOf,lastIndexOf,slice,toString 不会改 ...