Seek the Name, Seek the Fame
poj2752:http://poj.org/problem?id=2752
题意:给你一个串,让你求前n个字符和后n个字符相同的n有多少,从小到大输出来。
题解:这一题要深刻理解KMP的next数组,只有深刻理解,才能觉得比较轻松。推荐一个人的博客,这个人讲的比较好。
http://blog.csdn.net/zhang20072844/article/details/5779452
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=+;
int f[N],num[N],top;
char s[N];
int main(){
while(~scanf("%s",s)){
f[]=f[]=;top=;
int len=strlen(s);
for(int i=;i<len;i++){
int j=f[i];
while(j&&s[j]!=s[i])j=f[j];
f[i+]=(s[j]==s[i]?j+:);
}
int j=f[len];
num[++top]=len;
while(j!=){
num[++top]=j;
j=f[j];
}
for(int i=top;i>=;i--){
if(i==top)printf("%d",num[i]);
else
printf(" %d",num[i]);
}
printf("\n");
}
}
Seek the Name, Seek the Fame的更多相关文章
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
- poj-------------(2752)Seek the Name, Seek the Fame(kmp)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11831 Ac ...
- poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14106 Ac ...
- Seek the Name, Seek the Fame(Kmp)
Seek the Name, Seek the Fame Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (J ...
- poj 2752 Seek the Name, Seek the Fame(KMP需转换下思想)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10204 Ac ...
- poj2752 Seek the Name, Seek the Fame(next数组的运用)
题目链接:id=2752" style="color:rgb(202,0,0); text-decoration:none; font-family:Arial; font-siz ...
- POJ 2752 Seek the Name, Seek the Fame(next数组运用)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24000 ...
- POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
- POJ 2751:Seek the Name, Seek the Fame(Hash)
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24077 Ac ...
- (KMP)Seek the Name, Seek the Fame -- poj --2752
http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536 ...
随机推荐
- 【每日一linux命令8】添加新的工作组(groupadd)
groupadd (字意add group)增加一个新的工作组. 语法:groupadd 选项 用户组名 选项: -g 指定新建工作组的ID -r 创建系统工作组,系统工作组的ID小于500 -k 覆 ...
- Delphi系统托盘组件 TTrayIcon 简介
TTrayIcon 的主要属性: TrayIcon.Icon指定托盘图标, 有几种用法:1.设计时选择;2.把一个 TIcon 对象给它;3.使用当前程序图标: TrayIcon1.Icon := A ...
- java自定义对话框
package com.matp.view; import java.awt.FlowLayout; public class SimpleDialog extends JDialog impleme ...
- ubuntu vim YouComlpeteMe配置
使用vundle安装时,在.vimrc中添加 Plugin 'Valloric/YouCompleteMe' 使用Bundle会安装失败原因未知 YCM编译时附加选项--system-libclang ...
- Android(java)学习笔记195:学生信息管理系统案例(SQLite + ListView)
1.首先说明一个知识点,通常我们显示布局文件xml都是如下: setContentView(R.layout.activity_main): 其实每一个xml布局文件就好像一个气球,我们可以使用Vie ...
- colorAccent、colorPrimary、colorPrimaryDark actionbar toolbar navigationbar
伴随着Android5.0的发布也更新了support-v7-appcompat 到V21,其中增加了ToolBar.recyclerview.cardview等控件. Android5.0对改变AP ...
- NYOJ 47过河问题
主要思路:先排序.有两种可能是最小的情况,一种是让最小的去带着最大的过去,然后最小的再回来,还有一种就是先最小的和第二小的一块过去, 然后最小的回来,让最大的和第二大的过去,接着第二小的回来,第二小和 ...
- python简单小爬虫爬取易车网图片
上代码: import requests,urllib.request from bs4 import BeautifulSoup url = 'http://photo.bitauto.com/' ...
- Android关闭系统锁屏
昨晚探索了一下Android系统内的目录,意外发现系统锁屏的数据库 使用adb shell进入系统根目录 adb shell su sqlite3 data/system/locksettings.d ...
- CentOS6.6x86_64 部署 Nginx1.62+MySQL5.6.20+PHP5.6.4
准备工作 切换到管理员身份 su - 安装编译扩展 yum install -y gcc-c++ 创建数据库目录.代码目录 mkdir /mnt/data /mnt/www 安装Nginx 1.6.2 ...