POJ 2725
#include <iostream>
#include <string>
#include <algorithm>
#define MAXN 400005
using namespace std; char _m[MAXN];
int next[MAXN];
void give_next(int len);
int ans_len[MAXN];
int ans_len_index;
int ans[MAXN];
bool take_judge(int b,int len);
int main()
{
//freopen("acm.acm","r",stdin);
string s;
int i;
int j;
int len;
int index;
int cur;
//int ans;
while(getline(cin,s))
{
if(s.length() == )
{
break;
}
index = ;
//cout<<s<<endl;
//ans = 0;
//cout<<s<<endl;
for(i = ; i < s.length(); ++ i)
{
_m[i] = s[i];
}
memset(next,-,sizeof(next));
give_next(s.length()); i = s.length();
//cout<<i<<" ";
ans[index ++] = i;
for(; next[i] != ; i = next[i])
{
//cout<<next[i]<<" ";
ans[index++] = next[i];
}
for(i = index-; i >= ; -- i)
{
cout<<ans[i]<<" ";
}
cout<<ans[i]<<endl;
//cout<<endl;
// cout<<endl;
}
return ;
} bool take_judge(int b,int len)
{
int j = ;
int i;
for(i = b; i < len; ++ i,++ j)
{
if(_m[i] != _m[j])
{
break;
}
}
if(i == len)
{
return true;
}
return false;
} void give_next(int len) //此为求next 数组的方法。
{
int i;
int j;
i = ;
j = -;
next[] = -;
while(i < len)
{
if(j == - || _m[i] == _m[j])
{
i ++;
j ++;
next[i] = j;
}
else
j = next[j];
}
}
POJ 2725的更多相关文章
- poj 1279 半平面交核面积
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6668 Accepted: 2725 Descr ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- 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 ...
随机推荐
- 枚举子窗口EnumChildWindows()的应用
1.EnumChildWindows()函数的作用枚举子窗口(按顺序调用回调函数,并将子窗口的句柄传递给了回调函数).函数原型: BOOL WINAPI EnumChildWindows( HWND ...
- yyparse() and yylex()
Yacc 与 Lex 快速入门 yyparse() returns a value of 0 if the input it parses is valid according to the give ...
- gj13 asyncio并发编程
13.1 事件循环 asyncio 包含各种特定系统实现的模块化事件循环 传输和协议抽象 对TCP.UDP.SSL.子进程.延时调用以及其他的具体支持 模仿futures模块但适用于事件循环使用的Fu ...
- classmethod,staticmethod
'''1 绑定方法: 在类内部定义的函数,默认就是给对象来用,而且是绑定给对象用的,称为对象的绑定方法 绑定对象的方法特殊之处: 应该由对象来调用,对象来调用,会自动将对象当作第一个参数传入 绑定到类 ...
- bzoj2879(动态加边费用流)
参考题解:http://blog.csdn.net/yxuanwkeith/article/details/52254602 //开始跑费用流用的dijkstra,一直错,后来发现动态加边后我不会处理 ...
- noip第23课作业
1. 营救 铁塔尼号遇险了!他发出了求救信号.距离最近的哥伦比亚号收到了讯息,时间就是生命,必须尽快赶到那里. 通过侦测,哥伦比亚号获取了一张海洋图.这张图将海洋部分分化成n*n个比较小的单位,其 ...
- noip第6课作业
1. 数据统计 [问题描述] 输入N个整数,求出它们的最小值.最大值和平均值(保留3位小数).输入保证这些数都是不超过1000的整数.(1<=N<=1000) [样例输入] 8 2 ...
- ASP.NET MVC Owin 基本理解
一.OWIN OWIN(Open Web Interface for .Net),定义了一个服务器(IIS)和Web应用程序(MVC,Webform)通信的标准接口,并且通过抽象层使得这两个在微软平台 ...
- PL/SQL客户端连Oracle很快就断开问题的解决
PL/SQL登录很短时间session就自动断开 1.首先查看你这个用户的profile文件 select profile from dba_users where username='USERNAM ...
- Python 中的深拷贝和浅拷贝
一.浅拷贝python中 对象赋值时 默认是浅拷贝,满足如下规律:1. 对于 不可变对象(字符串,元组 等),赋值 实际上是创建一个新的对象:例如: >>> person=['nam ...