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 ...
随机推荐
- CHAPITRE II
J'ai ainsi vécu seul, sans personne avec qui parler véritablement, jusqu'à une panne[pan][机]故障 dans ...
- oracle在exp导出时报错PLS-00201: identifier 'EXFSYS.DBMS_EXPFIL_DEPASEXP' must be declared
报错如下信息: EXP-00008: ORACLE error 6550 encounteredORA-06550: line 1, column 14:PLS-00201: identifier ' ...
- RGB,YCBCR在HDMI传输线是数据排列
RGB4:4:4 YCbCr4:4:4 YCbCr4:2:2 YCbCr4:2:0
- 归并排序 JavaScript 实现
前文我们了解了快速排序算法的实现,本文我们来了解下另一种流行的排序算法-归并排序算法. 我们先来回顾下快排.快排的核心是找出一个基准元素,把数组中比该元素小的放到左边数组,比该元素大的放到右边数组,如 ...
- redis for lack of backlog
版本: redis-3.2.9 部署: 5台64G内存的物理机,每台机器启动2个redis进程组成5主5备集群,每台机器1个主1个备,并且错开互备. 问题: 发现redis进程占用内存高达40G,而且 ...
- C#窗体操作的小技巧
窗体在屏幕居中 ) - (), (Screen.GetBounds() - (), this.Width, this.Height, BoundsSpecified.Location);
- (转)MyEclipse10下创建web项目并发布到Tomcat
转自:http://blog.sina.com.cn/s/blog_699d3f1b01012spf.html MyEclipse10下创建web项目并发布到Tomcat 1.软件安装(不作详细描 ...
- (转)memcached的运行状态监控
转自:http://hi.baidu.com/software_one/item/e7e2b5846ba28bcaef083df3 当memcached启动起来并被访问后,如何知道其详细运行情况呢,详 ...
- POJ3616--Milking Time(动态规划)
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...
- unigui web app之菜单
unigui web app之菜单 拖放TUnimMenu控件到窗体上. side:=msleft 表示将在左边显示菜单. 菜单项属性 UnimMenu1.Visible := True;显示菜单 U ...