【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

航拍图像多类别实例分割数据集 一、基础信息 • 数据集名称:航拍图像多类别实例分割数据集 • 图片数量: 训练集:1283张图片 验证集:416张图片 总计:1699张航拍图片 • 训练集:1283张图片 • 验证集:416张图片 • 总计:1699张航拍图片 • 分类类别: 桥梁(Bridge) 田径场(GroundTrackField) 港口(Harbor) 直升机(Helicopter) 大型车辆(LargeVehicle) 环岛(Roundabout) 小型车辆(SmallVehicle) 足球场(Soccerballfield) 游泳池(Swimmingpool) 棒球场(baseballdiamond) 篮球场(basketballcourt) 飞机(plane) 船只(ship) 储罐(storagetank) 网球场(tennis_court) • 桥梁(Bridge) • 田径场(GroundTrackField) • 港口(Harbor) • 直升机(Helicopter) • 大型车辆(LargeVehicle) • 环岛(Roundabout) • 小型车辆(SmallVehicle) • 足球场(Soccerballfield) • 游泳池(Swimmingpool) • 棒球场(baseballdiamond) • 篮球场(basketballcourt) • 飞机(plane) • 船只(ship) • 储罐(storagetank) • 网球场(tennis_court) • 标注格式:YOLO格式,包含实例分割的多边形坐标,适用于实例分割任务。 • 数据格式:航拍图像数据。 二、适用场景 • 航拍图像分析系统开发:数据集支持实例分割任务,帮助构建能够自动识别和分割航拍图像中各种物体的AI模型,用于地理信息系统、环境监测等。 • 城市
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值