POJ3581 后缀数组
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 后缀数组的更多相关文章
- POJ3581 Sequence —— 后缀数组
题目链接:https://vjudge.net/problem/POJ-3581 Sequence Time Limit: 5000MS Memory Limit: 65536K Total Su ...
- POJ3581 Sequence(后缀数组)
题意:给一个串,串的第一个字符比后面的都大,要把它分成三段,然后反转每一段,求能得到的字典序最小的串是什么. 首先,第一段是可以确定的:把原串反转,因为第一个字符是最大的,它是唯一的,不存在反转串的后 ...
- 后缀数组的倍增算法(Prefix Doubling)
后缀数组的倍增算法(Prefix Doubling) 文本内容除特殊注明外,均在知识共享署名-非商业性使用-相同方式共享 3.0协议下提供,附加条款亦可能应用. 最近在自学习BWT算法(Burrows ...
- BZOJ 4199: [Noi2015]品酒大会 [后缀数组 带权并查集]
4199: [Noi2015]品酒大会 UOJ:http://uoj.ac/problem/131 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- POJ3693 Maximum repetition substring [后缀数组 ST表]
Maximum repetition substring Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9458 Acc ...
- POJ1743 Musical Theme [后缀数组]
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27539 Accepted: 9290 De ...
- 后缀数组(suffix array)详解
写在前面 在字符串处理当中,后缀树和后缀数组都是非常有力的工具. 其中后缀树大家了解得比较多,关于后缀数组则很少见于国内的资料. 其实后缀数组是后缀树的一个非常精巧的替代品,它比后缀树容易编程实现, ...
- 【UOJ #35】后缀排序 后缀数组模板
http://uoj.ac/problem/35 以前做后缀数组的题直接粘模板...现在重新写一下模板 注意用来基数排序的数组一定要开到N. #include<cstdio> #inclu ...
随机推荐
- Spring Boot 商城项目
Spring Boot 商城项目 angularJS Demo1 <html> <head> <title>angularJS Demo1</title> ...
- nodeJS删除文件
var fs = require("fs"); var path = require("path"); deleteFolderRecursive = func ...
- SAP全球企业官孙小群的生活智慧
转自:http://www.programmer.com.cn/15373/ 一下为程序员杂志对孙小群(Xiaoqun Clever)的采访. 最早接触计算机是在高中,那时发现通过一个小小的Basic ...
- Windows Server 2008 R2之五操作主控的管理
一.概述 操作主控(FSMO)也称作操作主机(OM),它是指在AD中一个或多个特殊的DC,用来执行某些特殊的功能(资源标识符SID分配.架构修改.PDC选择等). 1.操作主控的分类 基于森林的操作主 ...
- vue--自定义验证指令
参考文档: https://cn.vuejs.org/v2/guide/custom-directive.html https://www.cnblogs.com/ilovexiaoming/p/68 ...
- tomcat内存溢出:PermGen space解决方法
最近集群服务器中的几台服务器在半夜自动重启tomcat后一段时间便都会报java.lang.OutOfMemoryError: PermGen space. 习惯性的百度,得到的答案基本上都是统一的解 ...
- POJ-1322 Chocolate(概率DP)
Chocolate Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9279 Accepted: 2417 Special Jud ...
- POJ 1700 - Crossing River
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13982 Accepted: 5349 Description A gr ...
- 【Git 使用笔记】第三部分:多分支开发
###举例仓库 仓库地址A:git@gitlab.54php.cn:guowei/demos.git 仓库地址B:git@gitlab.54php.cn:infra/demos.git 开发人员仓库C ...
- short url短链接原理
一.什么是短链接 含义:就是把普通网址,转换成比较短的网址.比如:http://t.cn/RlB2PdD 这种,比如:微博:这些限制字数的应用里都用到这种技术. 优点:短.字符少.美观.便于发布.传播 ...