首页 技术 正文
技术 2022年11月21日
0 收藏 598 点赞 3,826 浏览 1527 个字

最小表示法就是直接扫过去

后缀自动机就是每次找最字典序最小儿子输出

  • 最小表示法
/*
最小表示法裸题, 我好像学过来着?? 怎么忘得这么干净*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 300010
#define mmp make_pair
using namespace std;
int read()
{
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int s[M];int work(int n)
{
int i = 0, j = 1, k = 0;
while(i < n && j < n && k < n)
{
int t = s[(i + k) % n] - s[(j + k) % n];
if(t == 0)
{
k++;
}
else
{
if(t > 0) i += k + 1;
else j += k + 1;
if(i == j) j++;
k = 0;
}
}
return i < j ? i : j;
}int main()
{
int len = read();
for(int i = 0; i < len; i++) s[i] = read();
int x = work(len);
int tmp = -1;
for(int y = x; y != tmp; y = (y + 1) % len)
{
cout << s[y] << " ";
tmp = x;}
return 0;
}
  • 后缀自动机
/*
最小表示法裸题, 我好像学过来着?? 怎么忘得这么干净*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#include<map>
#define ll long long
#define M 300010
#define mmp make_pair
using namespace std;
int read()
{
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int s[M];
int len[4 * M], fa[4 * M], cnt = 1, lst = 1;
map<int, int> ch[4 * M];
void insert(int c)
{
int p = ++cnt, f = lst;
lst = p;
while(f && !ch[f][c]) ch[f][c] = p, f = fa[f];
if(!f)
{
fa[p] = 1;
}
else
{
int q = ch[f][c];
if(len[q] == len[f] + 1)
{
fa[p] = q;
}
else
{
int nq = ++cnt;
fa[nq] = fa[q];
ch[nq] = ch[q];
len[nq] = len[f] + 1;
fa[p] = fa[q] = nq;
while(f && ch[f][c] == q) ch[f][c] = nq, f = fa[f];
}
}
}int main()
{
int len = read();
for(int i = 0; i < len; i++) s[i] = read(), insert(s[i]);
for(int i = 0; i < len; i++) insert(s[i]);
int now = 1;
for(int i = 0; i < len; i++)
{
cout << ch[now].begin()->first << " ";
now = ch[now].begin()->second;
}
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844