【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

个人防护装备实例分割数据集 一、基础信息 • 数据集名称:个人防护装备实例分割数据集 • 图片数量: 训练集:4524张图片 • 训练集:4524张图片 • 分类类别: 手套(Gloves) 头盔(Helmet) 未戴手套(No-Gloves) 未戴头盔(No-Helmet) 未穿鞋(No-Shoes) 未穿背心(No-Vest) 鞋子(Shoes) 背心(Vest) • 手套(Gloves) • 头盔(Helmet) • 未戴手套(No-Gloves) • 未戴头盔(No-Helmet) • 未穿鞋(No-Shoes) • 未穿背心(No-Vest) • 鞋子(Shoes) • 背心(Vest) • 标注格式:YOLO格式,适用于实例分割任务,包含边界框或多边形坐标。 • 数据格式:图片数据,来源于监控或相关场景。 二、适用场景 • 工业安全监控系统开发:用于自动检测工人是否佩戴必要的个人防护装备,提升工作场所安全性,减少工伤风险。 • 智能安防应用:集成到监控系统中,实时分析视频流,识别PPE穿戴状态,辅助安全预警。 • 合规性自动化检查:在建筑、制造等行业,自动检查个人防护装备穿戴合规性,支持企业安全审计。 • 计算机视觉研究:支持实例分割、目标检测等算法在安全领域的创新研究,促进AI模型优化。 三、数据集优势 • 类别全面:覆盖8种常见个人防护装备及其缺失状态,提供丰富的检测场景,确保模型能处理各种实际情况。 • 标注精准:采用YOLO格式,每个实例都经过精细标注,边界框或多边形坐标准确,提升模型训练质量。 • 真实场景数据:数据来源于实际环境,增强模型在真实世界中的泛化能力和实用性。 • 兼容性强:YOLO格式便于与主流深度学习框架(如YOLO、PyTorch等)集成,支持快速部署和实验。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值