http://poj.org/problem?id=3581

这题说是给了N个数字组成的序列A1 A2 ..An 其中A1 大于其他的数字 , 现在要把序列分成三段并将每段分别反转求最小字典序

以后还是老老实实用基数排序 用sort wa 了 一晚

#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <vector>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
const int maxn =;
struct SuffixArry
{
int c[maxn*],t[maxn*],t1[maxn*],sa[maxn*];
void build(int n,int m,int *S)
{
int *x=t,*y=t1,i;
for( i=; i<m; i++)c[i]=;
for( i=; i<n; i++)c[x[i]=S[i] ]++;
for( i=; i<m; i++)c[i]+=c[i-];
for( i=n-; i>=; i--)sa[ --c[ x[i] ] ]=i;
int p;
for(int k=; k<=n; k<<= )
{
p=;
for( i = n-k; i<n; i++)y[p++]=i;
for( i=; i<n; i++) if(sa[i]>=k)y[p++]=sa[i]-k;
for( i=; i<m; i++)c[ i ] = ;
for( i= ; i<n; i++ )c[ x[ y[i] ] ]++;
for( i=; i<m; i++) c[i]+=c[i-];
for( i=n-; i>=; i--) sa[--c[ x[ y[i] ] ] ]=y[i];
swap(x,y);
p=; x[ sa[ ] ] = ;
for(int i=; i<n; i++)
x[ sa[i] ] = y[ sa[i] ]== y[ sa[i-] ]&& y[ sa[i]+k ]==y[sa[i-]+k]?p-:p++;
if(p>=n)break;
m=p;
}
}
void clear(){
memset(t,-,sizeof(t));
memset(t1,-,sizeof(t1));
}
}T;
int A[maxn],B[maxn],C[maxn],rev[maxn*];
void revercopy(int *a, int *b, int len)
{
for(int i=; i<len; i++)
{
b[i]=a[len--i];
}
}
void rever(int *a, int len)
{
for(int i=; i<len/; i++ )
{
int t= a[i];
a[i]=a[len--i];
a[len--i]=t;
}
}
int main(int argc, char *argv[]) { int n;
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%d",&A[i]);
B[i]=A[i];
}
sort(B,B+n);
int L=unique(B,B+n)-B;
for(int i=; i<n; i++)
{
C[i]=lower_bound(B,B+L,A[i])-B;
}
int p1;
T.clear();
revercopy(C,rev,n);
T.build(n,L,rev); for(int i=; i<n; i++)
{
p1 = n-T.sa[i];
if(p1>&&n-p1>=)break;
} if(p1<||n-p1<)while(true){};
int m= n-p1;
revercopy(C+p1,rev,m); //for(int i=0; i<m; i++)printf("%d ",rev[i]);
revercopy(C+p1,rev+m,m);//for(int i=0; i<m*2; i++)printf("%d ",rev[i]);
T.build(m*,L,rev);
int p2;
for(int i=; i<m*; i++)
{
p2 = p1 + m - T.sa[ i ];
if(p2>p1&&n-p2>=)break;
}
if(p2<=p1||n-p2<)while(true){
};
rever(A,p1);
rever(A+p1,p2-p1);
rever(A+p2,n-p2);
for(int i=; i<n; i++) printf("%d\n",A[i]);
return ;
}

POJ3581 后缀数组的更多相关文章

  1. POJ3581 Sequence —— 后缀数组

    题目链接:https://vjudge.net/problem/POJ-3581 Sequence Time Limit: 5000MS   Memory Limit: 65536K Total Su ...

  2. POJ3581 Sequence(后缀数组)

    题意:给一个串,串的第一个字符比后面的都大,要把它分成三段,然后反转每一段,求能得到的字典序最小的串是什么. 首先,第一段是可以确定的:把原串反转,因为第一个字符是最大的,它是唯一的,不存在反转串的后 ...

  3. 后缀数组的倍增算法(Prefix Doubling)

    后缀数组的倍增算法(Prefix Doubling) 文本内容除特殊注明外,均在知识共享署名-非商业性使用-相同方式共享 3.0协议下提供,附加条款亦可能应用. 最近在自学习BWT算法(Burrows ...

  4. BZOJ 4199: [Noi2015]品酒大会 [后缀数组 带权并查集]

    4199: [Noi2015]品酒大会 UOJ:http://uoj.ac/problem/131 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 ...

  5. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  6. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  7. POJ1743 Musical Theme [后缀数组]

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27539   Accepted: 9290 De ...

  8. 后缀数组(suffix array)详解

    写在前面 在字符串处理当中,后缀树和后缀数组都是非常有力的工具. 其中后缀树大家了解得比较多,关于后缀数组则很少见于国内的资料. 其实后缀数组是后缀树的一个非常精巧的替代品,它比后缀树容易编程实现, ...

  9. 【UOJ #35】后缀排序 后缀数组模板

    http://uoj.ac/problem/35 以前做后缀数组的题直接粘模板...现在重新写一下模板 注意用来基数排序的数组一定要开到N. #include<cstdio> #inclu ...

随机推荐

  1. Unity3D Animator控制参数和添加事件

    Animator控制参数和添加事件 using UnityEngine; using System.Collections; public class AniControl : MonoBehavio ...

  2. Setting up Unicorn with Nginx

    gem install unicorn or gem 'unciron' 1 install Nginx yum install ... 2 Configuration vi /etc/nginx/n ...

  3. Yet another way to manage your NHibernate ISessionFactory

    So here is my current UnitOfWork implementation.  This one makes use of the somewhat new current_ses ...

  4. flask跨域请求

    跨域文件上传的时候,浏览器会自动发起一个 OPTIONS 方法到服务器,现在后台解决前端跨域解决前端跨域请求的问题 客户端发起的这个 OPTIONS 可以说是一个“预请求”,用于探测后续真正需要发起的 ...

  5. 转sklearn保存模型

    训练好了一个Model 以后总需要保存和再次预测, 所以保存和读取我们的sklearn model也是同样重要的一步. 比如,我们根据房源样本数据训练了一下房价模型,当用户输入自己的房子后,我们就需要 ...

  6. Kendo UI使用小小记

    之所以说小小记,是因为我根本没有好好用它,只是正好前些日子接触了一下,觉得还不错,随手记记~ 契机 我从加入现在这个公司以来,半专业的承担了很多前端相关的事情,用过不少前端框架,也为框架和原生的页面写 ...

  7. ELKStack生产案例

    需求分析: 访问日志:apache访问日志,nginx访问日志,tomcat file 错误日志: error log,java日志 直接收 java异常需要处理 系统日志:/var/log/*   ...

  8. HDU 1789 - Doing Homework again - [贪心+优先队列]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  9. Oracle安装部署之linux OS install oracle database安装脚本

    #!/bin/bash#Purpose:Create and config oracle install.#Usage:Log on as the superuser('root') #1.creat ...

  10. 网络层 运输层 NAT路由器 NATP路由器 一根光纤 多个固定ip

    长城宽带想要公网和固定ip的来看看吧.[迅雷赚钱宝吧]_百度贴吧 https://tieba.baidu.com/p/4035318158?red_tag=0898389066 连续电话投诉加咨询一周 ...