fzu 2128
第一组实例
aaaa
2
aa
aa
第二组
a
1
c
第三组
abcdef
2
abcd
bcd
第四组
abcdef
2
abcd
bcde
第五组
aaaa
2
a
aa
第六组
lgcstraightlalongahisnstreet
5
str
long
tree
biginteger
ellipse
#include<stdio.h>
#include<string.h>//考虑了很多实例
#include<stdlib.h>
#define N 1100000
char s[N],str[1100][200];
struct node {
int start,end,index;
}hst[N],hen[N];
int cmp(const void *a,const void *b) {
return (*(struct node *)a).start>(*(struct node *)b).start?1:-1;
}
int compare(const void *a,const void *b) {
return (*(struct node *)a).end>(*(struct node *)b).end?1:-1;
}
int main() {
int n,max,index,to,ans,start,end,i,j;
while(scanf("%s",s)!=EOF) {
scanf("%d",&n);
index=0;
for(i=0;i<n;i++) {
scanf("%s",str[i]);
to=0;
for(j=0;j<i;j++)
if(strcmp(str[j],str[i])==0)//第一组
to=1;
if(to)
continue;
while(1) {
if(strstr(s+to,str[i])==NULL)
break;
hst[index].index=index;
hst[index].start=strstr(s+to,str[i])-&s[0];
hst[index].end=hst[index].start+strlen(str[i])-1;
hen[index]=hst[index];
to=hst[index].start+1;
index++;
}
}
if(index==0) {//第二组
printf("%d\n",strlen(s));
continue;
}
qsort(hst,index,sizeof(hst[0]),cmp);
qsort(hen,index,sizeof(hen[0]),compare);
start=hen[0].end;
end=strlen(s)-hst[index-1].start-1;
max=end>start?end:start;
for(i=0;i<index;i++) {
ans=0;
for(j=0;j<index;j++)
if(hen[j].index!=hst[i].index&&hen[j].end>=hst[i].start) {
ans=hen[j].end-hst[i].start-1;
break;
}
if(max<ans)
max=ans;
}
printf("%d\n",max);
}
return 0;
}
fzu 2128的更多相关文章
- fzu 2128 AC自动机
链接 http://acm.fzu.edu.cn/problem.php?pid=2128 解题方法 首先考虑暴力,,就是拿每一个字符串在匹配串里面找到所有位置,然后从头到尾不断更新最长的合理位 ...
- 福州大学第十届校赛 & fzu 2128最长子串
思路: 对于每个子串,求出 母串中 所有该子串 的 开始和结束位置,保存在 mark数组中,求完所有子串后,对mark数组按 结束位置排序,然后 用后一个的结束位置 减去 前一个的 开始 位置 再 减 ...
- FZU 2128 最长子串
题目链接:最长子串 思路:依次找出每个子串的在字符串中的首尾地址,所有子串先按照尾地址从小到大排序.然后首地址从小到大排. 遍历一遍每个子串的首地址和它后面相邻子串的尾地址之差-1, 第一个子串的首地 ...
- 最长子串(FZU2128)
最长子串 Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status ...
- fzu Problem 2128 最长子串(KMP + strstr 经典好题)
Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长. Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- FZU 2112 并查集、欧拉通路
原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...
随机推荐
- RDA 字库制作
制作韩语字库为例: 1.韩语UNICODE 范围 TV_IDF_uni_korean.txt [01fa,] [02c6,02c7] [02c9,02ca] [02cd,02cd] [02d8,02d ...
- openstack instance resize Resize error: Unable to resize disk down
- IDEA Spark Streaming 操作(套接字流)-----make socket数据源
import java.io.PrintWriter import java.net.ServerSocket import scala.io.Source object DStream_makeSo ...
- 46. Ext中namespace的作用(转)
转自:https://www.cnblogs.com/givemeanorange/p/5569954.html Ext中在每一个页面中添加一个namespace呢,就像下面的代码: // creat ...
- Vue.js经典开源项目汇总-前端参考资源
Vue.js经典开源项目汇总 原文链接:http://www.cnblogs.com/huyong/p/6517949.html Vue是什么? Vue.js(读音 /vjuː/, 类似于 view) ...
- P2068 统计和
P2068 统计和 这题真的非常水了 如果不会 右转[模板]树状数组 2 基本上是一模一样的 #include <bits/stdc++.h> #define lowbit(x) x&am ...
- ZOJ3714JavaBeans
#!/usr/bin/env python # encoding: utf-8 t = int(raw_input()) for i in range(t): n,k = [int(x) for x ...
- EF--DBFirst
EF框架有三种基本的方式:DB First,Model First,Code First.这里简单的说一下DB First,适合没有基础的同学照着做,学习基础的东西. DatabaseFirst就是围 ...
- Spark 概念学习系列之Spark基本概念和模型(十八)
打好基础,别小瞧它! spark的运行模式多种多样,在单机上既可以本地模式运行,也可以伪分布模式运行.而当以分布式的方式在集群中运行时.底层的资源调度可以使用Mesos或者Yarn,也可使用spark ...
- JAVA FORK JOIN EXAMPLE--转
http://www.javacreed.com/java-fork-join-example/ Java 7 introduced a new type of ExecutorService (Ja ...