【POJ2752】【KMP】Seek the Name, Seek the Fame

本文介绍了一种用于寻找字符串中既是前缀又是后缀的子串的算法,并提供了详细的实现代码。该算法通过构建next数组来高效地解决这一问题,可用于自动为新生儿起名等有趣的应用场景。

Description

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm: 

Step1. Connect the father's name and the mother's name, to a new string S. 
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S). 

Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:) 

Input

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above. 

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000. 

Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.

Sample Input

ababcababababcabab
aaaaa

Sample Output

2 4 9 18
1 2 3 4 5

Source

【分析】
简单的应用,转个弯就过来了。
从总长度开始一直next就可以了。注意总长度也是符合条件的
 1 /*
 2 登科后
 3 唐代
 4 孟郊
 5 
 6 昔日龌龊不足夸,今朝放荡思无涯。 
 7 春风得意马蹄疾,一日看尽长安花。 
 8 */
 9 #include <iostream>
10 #include <cstdio>
11 #include <algorithm>
12 #include <cstring>
13 #include <vector>
14 #include <utility>
15 #include <iomanip>
16 #include <string>
17 #include <cmath>
18 #include <queue>
19 #include <assert.h>
20 #include <map>
21 #include <ctime>
22 #include <cstdlib>
23 #include <stack>
24 #define LOCAL
25 const int MAXN = 400000 + 10;
26 const int INF = 100000000;
27 const int SIZE = 450;
28 const int MAXM = 1000000 + 10;
29 const int maxnode =  0x7fffffff + 10;
30 using namespace std;
31 int l1, l2;
32 char a[MAXN];
33 int next[MAXN];//不用开太大了.. 
34 int Ans[MAXN];
35 void getNext(){
36      //初始化next数组 
37      next[1] = 0;
38      int j = 0;
39      for (int i = 2; i <= l1; i++){
40          while (j > 0 && a[j + 1] != a[i]) j = next[j];
41          if (a[j + 1] == a[i]) j++;
42          next[i] = j;
43      }
44      return;
45 }
46 /*int kmp(){
47     int j = 0, cnt = 0;
48     for (int i = 1; i <= l2; i++){
49         while (j > 0 && a[j + 1] != b[i]) j = next[j];
50         if (a[j + 1] == b[i]) j++;
51         if (j == l1){
52            cnt++;
53            j = next[j];//回到上一个匹配点 
54         }
55     }
56     return cnt;
57 }*/
58 
59 /*void init(){
60      scanf("%s", a + 1);
61      scanf("%s", b + 1);
62      l1 = strlen(a + 1);
63      l2 = strlen(b + 1);
64 }*/
65 
66 int main(){
67     int T;
68     
69     while (scanf("%s", a + 1) != EOF){
70           int tot = 0;
71           l1 = strlen(a + 1);
72           getNext();
73           int tmp = next[l1];
74           if (tmp != 0) Ans[tot++] = tmp;
75           while (next[tmp] != 0){
76                 tmp = next[tmp];
77                 Ans[tot++] = tmp; 
78           } 
79           for (int i = tot - 1; i >= 0; i--) printf("%d ", Ans[i]); 
80           printf("%d\n", l1);
81     }
82     /*scanf("%s", a + 1);
83     l1 = strlen(a + 1);
84     getNext();
85     for (int i = 1; i <= l1; i++) printf("%d" , next[i]);*/
86     return 0;
87 }
View Code

 

转载于:https://www.cnblogs.com/hoskey/p/4333433.html

一、基础信息 数据集名称:Bottle Fin实例分割数据集 图片数量: 训练集:4418张图片 验证集:1104张图片 总计:5522张图片 分类类别: - 类别0: 数字0 - 类别1: 数字1 - 类别2: 数字2 - 类别3: 数字3 - 类别4: 数字4 - 类别5: 数字5 - 类别6: Bottle Fin 标注格式:YOLO格式,包含多边形坐标,适用于实例分割任务。 数据格式:图片格式常见如JPEG或PNG,具体未指定。 二、适用场景 实例分割AI模型开发:数据集支持实例分割任务,帮助构建能够精确识别和分割图像中多个对象的AI模型,适用于对象检测和分割应用。 工业自动化与质量控制:可能应用于制造、物流或零售领域,用于自动化检测和分类物体,提升生产效率。 计算机视觉研究:支持实例分割算法的学术研究,促进目标检测和分割技术的创新。 教育与实践培训:可用于高校或培训机构的计算机视觉课程,作为实例分割任务的实践资源,帮助学生理解多类别分割。 三、数据集优势 多类别设计:包含7个不同类别,涵盖数字和Bottle Fin对象,增强模型对多样对象的识别和分割能力。 高质量标注:标注采用YOLO格式的多边形坐标,确保分割边界的精确性,提升模型训练效果。 数据规模适中:拥有超过5500张图片,提供充足的样本用于模型训练和验证,支持稳健的AI开发。 即插即用兼容性:标注格式直接兼容主流深度学习框架(如YOLO),便于快速集成到各种实例分割项目中。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值