BZOJ-1031: [JSOI2007]字符加密Cipher(后缀数组模版)

题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1031

思路:加倍成环,然后跑一次后缀数组就好了。****

******第一次写后缀数组,写得很渣。。代码长,速度又慢。。。******

代码1:****(基数排序写得好长555 速度还渣得可怜: ):

dcc451da81cb39dbc818087cd2160924ab18303b.jpg.png

#include 
#include 
#include 
#include 
#include 
 
using namespace std;
 
#define MAXN 200001
#define Bit(x)(int(log(x)/log(10))+1)
#define Digit(x,y)((x/EXP[y-1])%10)
 
struct saver {
    int x,y,t;
} b[MAXN];
 
char s[MAXN],c[MAXN];
int n,m;
 
int sa[MAXN],rank[MAXN];
int EXP[10];
 
saver w[2][10][MAXN];
int num[2][10];
 
void Sort() {
    int d1=0,d2=0,k=0;
    memset(num,0,sizeof(num));
    num[k][0]=m;
    for (int i=0;i++

代码2:(的sort()代替基数排序):

3812b31bb051f81928b56d60d8b44aed2e73e70c.jpg.png
#include 

#include 

#include 

#include 

#include 

 

using namespace std;

 

#define MAXN 200001

#define Bit(x)(int(log(x)/log(10))+1)

#define Digit(x,y)((x/EXP[y-1])%10)

 

struct saver {

    int x,y,t;

} b[MAXN];

 

char s[MAXN],c[MAXN];

int n,m;

 

int sa[MAXN],rank[MAXN];

int EXP[10];

 

saver w[2][10][MAXN];

int num[2][10];

 

bool Cmp(saver x,saver y) {

        return (x.x

基数排序:

#include 

#include 

#include 

#include 

#include 

   

using namespace std;

   

#define MAXN 200001

#define Bit(x)(int(log(x)/log(10))+1)

#define Digit(x,y)((x/EXP[y-1])%10)

   

char s[MAXN],c[MAXN];

int n,m;

   

int sa[MAXN],rank[MAXN],x[MAXN],y[MAXN],b=1,w[MAXN],r[MAXN],e[MAXN];

   

void Sa() {

    int M=m,N;

    bool flag;

    for (int i=0;i++

你可能感兴趣的:(BZOJ-1031: [JSOI2007]字符加密Cipher(后缀数组模版))