fzu1901Period II
地址:http://acm.fzu.edu.cn/problem.php?pid=1901
题目:
Accept: 442 Submit: 1099
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
S[i]=S[i+P] for i in [0..SIZE(S)-p-1],
then the prefix is a “period” of S. We want to all the periodic prefixs.
Input
The first line contains an integer T representing the number of cases. Then following T cases.
Each test case contains a string S (1 <= SIZE(S) <= 1000000),represents the title.S consists of lowercase ,uppercase letter.
Output
Sample Input
ooo
acmacmacmacmacma
fzufzufzuf
stostootssto
Sample Output
1 2 3
Case #2: 6
3 6 9 12 15 16
Case #3: 4
3 6 9 10
Case #4: 2
9 12
Source
FOJ有奖月赛-2010年05月
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
const double eps=1e-;
const int K=1e6+;
const int mod=1e9+; int nt[K],ans[K];
char sa[K];
void kmp_next(char *T,int *next)
{
next[]=;
for(int i=,j=,len=strlen(T);i<len;i++)
{
while(j&&T[i]!=T[j]) j=next[j-];
if(T[i]==T[j]) j++;
next[i]=j;
}
}
int kmp(char *S,char *T,int *next)
{
int ans=;
int ls=strlen(S),lt=strlen(T);
for(int i=,j=;i<ls;i++)
{
while(j&&S[i]!=T[j]) j=next[j-];
if(S[i]==T[j]) j++;
if(j==lt) ans++;
}
return ans;
} int main(void)
{
int t,cnt=;cin>>t;
while(t--)
{
scanf("%s",sa);
kmp_next(sa,nt);
int len=strlen(sa),k=;
int tk=len;
while(nt[tk-]>)
ans[k++]=len-nt[tk-],tk=nt[tk-];
ans[k++]=len;
printf("Case #%d: %d\n",cnt++,k);
for(int i=;i<k;i++)
printf("%d%c",ans[i],i!=k-?' ':'\n');
}
return ;
}
fzu1901Period II的更多相关文章
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II
题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...
- 函数式Android编程(II):Kotlin语言的集合操作
原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...
- 统计分析中Type I Error与Type II Error的区别
统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- [LeetCode] Number of Islands II 岛屿的数量之二
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
随机推荐
- WPF DataGrid DataGridTemplateColumn 控制模板中控件
<DataGrid Name="DG"> <DataGrid.Columns> < ...
- 使用CAtlRegExp类进行密码校验
前言 最近做了一个小需求,新建用户时输入的密码必须包含数字.小写字母.大写字符以及特殊字符,目的是为了增强密码的强度,如果没有其中一项,就需要弹出窗口进行提示. 正则表达式 对于此类 ...
- FCN 分割网络详解
博客来源于:https://www.cnblogs.com/gujianhan/p/6030639.html: https://blog.csdn.net/sinat_24143931/article ...
- videoview 播放视频
-videoVIew 继承SurfaceView 使用android的VideoView来播放一个视频,步骤是: 1,在xml中创建一个videoView, 2,在java中导入,然后创建一个Medi ...
- 实现 IteratorAggregate接口
<?php class MyIterator implements Iterator{ private $var = array(); public function __construct($ ...
- CreateRemoteThreadex开启远程线程失败集合
修改进程PE头 报错 修改进程_EPROCESS +0x12c SectionBaseAddress : 0x00bf0000 都会报错 不是有效的win32程序 错误号193 修改进程PEB +0x ...
- 【BZOJ4606】[Apio2008]DNA DP
[BZOJ4606][Apio2008]DNA Description 分析如DNA序列这样的生命科学数据是计算机的一个有趣应用.从生物学的角度上说,DNA 是一种由腺嘌呤.胞嘧啶.鸟嘌呤和胸腺嘧啶这 ...
- 【BZOJ4155】[Ipsc2015]Humble Captains 最小割+DP
[BZOJ4155][Ipsc2015]Humble Captains Description 每天下午放学时都有n个zky冲出教室去搞基.搞基的zky们分成两队,编号为1的zky是1号队的首领,编号 ...
- 【POJ2516】Minimum Cost
[POJ2516]Minimum Cost 题意:有N个收购商.M个供应商.K种物品.对于每种物品,每个供应商的供应量和每个收购商的需求量已知.每个供应商与每个收购商之间运送该物品的运费已知.求满足收 ...
- js功能实现的特效--距离新年还有多少天
代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...