日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[LA3026]Period

發布時間:2025/4/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [LA3026]Period 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

[LA3026]Period

試題描述

For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 ≤ i ≤ N) we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as AK, that is A concatenated K times, for some string A. Of course, we also want to know the period K.

輸入

The input file consists of several test cases. Each test case consists of two lines. The first one contains N (2 ≤ N ≤ 1000000) the size of the string S. The second line contains the string S. The input file ends with a line, having the number zero on it.

輸出

For each test case, output ‘Test case #’ and the consecutive test case number on a single line; then, for each prefix with length i that has a period K > 1, output the prefix size i and the period K separated by a single space; the prefix sizes must be in increasing order. Print a blank line after each test case.

輸入示例

3 aaa 12 aabaabaabaab 0

輸出示例

Test case #1 2 2 3 3Test case #2 2 2 6 2 9 3 12 4

數據規模及約定

見“輸入

題解

KMP 裸題,對于位置 i,它指向的失配的位置為 f[i+1],那么當 f[i+1] > 1 且 (i - f[i+1] + 1) | i 時答案為 i / (i - f[i+1] + 1). 我 KMP 從 1 開始做的所以前面的式子可能會奇怪一些。

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <stack> #include <vector> #include <queue> #include <cstring> #include <string> #include <map> #include <set> using namespace std;int read() {int x = 0, f = 1; char c = getchar();while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }return x * f; }#define maxn 1000010 int n, f[maxn]; char S[maxn];int main() {n = read();int kase = 0; // bool fl = 1;while(n) {scanf("%s", S + 1); // if(!fl) putchar('\n'); fl = 0;printf("Test case #%d\n", ++kase);f[1] = f[2] = 1;for(int i = 2; i <= n; i++) {int u = f[i];while(u > 1 && S[u] != S[i]) u = f[u];f[i+1] = S[u] == S[i] ? u + 1 : u;if(f[i+1] > 1 && i % (i + 1 - f[i+1]) == 0) printf("%d %d\n", i, i / (i + 1 - f[i+1]));}putchar('\n');n = read();}return 0; }

?

轉載于:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/5753884.html

總結

以上是生活随笔為你收集整理的[LA3026]Period的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 97国产精品视频 | 91传媒在线免费观看 | 好色成人网 | 欧洲中文字幕日韩精品成人 | 亚洲精品久久久久久国 | 精品国产乱子伦一区二区 | 麻豆视频在线 | 大学生三级中国dvd 日韩欧美一区二区区 | 蜜桃视频成人 | 日韩中文字幕在线观看 | 福利一区在线观看 | 亚洲视频一区二区三区四区 | 国产一区二区视频免费观看 | 在线观看亚洲大片短视频 | 欧美日韩久久久久 | 华丽的外出在线观看 | 国产a免费 | 激情小视频 | 97精品一区二区视频在线观看 | 中文字幕网伦射乱中文 | 亚洲一区av在线 | 亚洲性综合 | 日本少妇性高潮 | 韩日一区 | 精品一区二区三区视频 | 亚洲成人av一区 | 国产精品一区二区三区在线播放 | 福利av在线| 性猛交富婆╳xxx乱大交麻豆 | hd极品free性xxx护士 | 国产精品日韩专区 | 亚洲美女视频网站 | 日本欧美国产一区二区三区 | gogo人体做爰大胆视频 | 国产成人午夜精华液 | 欧美日韩在线精品 | 日本大胆人体视频 | 亚洲av成人精品午夜一区二区 | 男人喷出精子视频 | 果冻av在线 | 伊人网在线视频观看 | 国内成人av | 中文字幕在线乱 | 国产精品久久久久久久久久久久久久 | 亚洲观看黄色网 | 五月婷婷丁香激情 | 国产精品中文字幕在线 | 蜜桃久久久久 | 魔女鞋交玉足榨精调教 | 国产视频aaa | 天天草夜夜操 | 国产精品福利在线观看 | 美国一区二区三区 | 人妻少妇偷人精品久久性色 | 男女无套免费视频网站动漫 | 韩国电影一区 | 玖玖热在线视频 | 成人精品综合 | 二区影院| 精品午夜久久 | 免费高清黄色 | 国产视频福利在线 | 青青草华人在线视频 | 久久精品牌麻豆国产大山 | 亚洲精品国产综合 | 铠甲勇士猎铠 | 色图自拍偷拍 | 亚洲日本视频在线观看 | 91华人在线 | 99国产精品免费 | 日本不卡专区 | 日韩免费观看av | 成人免费无码大片a毛片 | 日韩一区二区免费在线观看 | 中出在线| 中文字幕一区二区三区四区欧美 | 中文字幕国产综合 | 欧美电影一区 | 欧美在线一二三四区 | 亚洲精品88 | 性大片潘金莲裸体 | 捆绑最紧bdsm视频 | 九九视频精品在线 | 91精品国自产在线 | 伊人网大香 | 99精品免费观看 | 男人插女人免费视频 | 奶波霸巨乳一二三区乳 | 欧美在线观看免费高清 | 日韩在线导航 | 无遮挡无掩盖网站 | 亚洲一区二区三区高清在线 | 西西444www大胆无视频 | 五月天久久 | 俺也去在线视频 | 亚洲一区图片 | 在线播放av网址 | 噜噜色图| 国产一区不卡在线观看 |