bzoj1031[JSOI2007]字符加密Cipher(拆环变链,利用sa数组)
来源:互联网 发布:路由器mac 编辑:程序博客网 时间:2024/06/03 19:13
挺裸的一道后缀数组。。注意是环,把他在后面复制一遍再做就好了。。
#include <cstdio>#include <cstring>#define N 200005char s[N];int n,rank[N<<1],st[256],rank1[N],count[N],sa[N],tmp[N];int main(){//freopen("a.in","r",stdin);scanf("%s",s+1);n=strlen(s+1);for(int i=1;i<=n;++i) s[n+i]=s[i];n<<=1;memset(st,0,sizeof(st));memset(rank,0,sizeof(rank));memset(rank1,0,sizeof(rank1));for(int i=1;i<=n;++i) st[s[i]]=1;for(int i=1;i<=255;++i) st[i]+=st[i-1];for(int i=n;i>=1;--i) rank[i]=st[s[i]];int k=1;for(int p=1;k!=n;p<<=1){memset(count,0,sizeof(count));for(int i=1;i<=n;++i) count[rank[i+p]]++;for(int i=1;i<=n;++i) count[i]+=count[i-1];for(int i=n;i>=1;--i) tmp[count[rank[i+p]]--]=i;memset(count,0,sizeof(count));for(int i=1;i<=n;++i) count[rank[tmp[i]]]++;for(int i=1;i<=n;++i) count[i]+=count[i-1];for(int i=n;i>=1;--i) sa[count[rank[tmp[i]]]--]=tmp[i];memcpy(rank1,rank,sizeof(rank1));rank[sa[1]]=k=1;for(int i=2;i<=n;++i){if(rank1[sa[i]]!=rank1[sa[i-1]]||rank1[sa[i]+p]!=rank1[sa[i-1]+p]) ++k;rank[sa[i]]=k;}}for(int i=1;i<=n;++i){if(sa[i]<=(n>>1)) printf("%c",s[sa[i]+n/2-1]);}return 0;}
阅读全文
0 0
- bzoj1031[JSOI2007]字符加密Cipher(拆环变链,利用sa数组)
- [BZOJ1031][JSOI2007]字符加密Cipher && 后缀数组
- [JSOI2007] [BZOJ1031] 字符加密Cipher - 后缀数组
- BZOJ1031 [JSOI2007]字符加密Cipher 后缀数组
- [BZOJ1031][[JSOI2007]字符加密Cipher] 后缀数组
- BZOJ1031[JSOI2007]字符加密Cipher 后缀数组
- [bzoj1031][JSOI2007]字符加密Cipher 后缀数组
- [BZOJ1031][JSOI2007]字符加密Cipher(后缀数组)
- bzoj1031: [JSOI2007]字符加密Cipher(后缀数组)
- BZOJ1031: [JSOI2007]字符加密Cipher
- [Bzoj1031][JSOI2007]字符加密Cipher
- [bzoj1031][JSOI2007]字符加密Cipher
- [BZOJ1031][JSOI2007]字符加密Cipher
- bzoj1031: [JSOI2007]字符加密Cipher
- 【JSOI2007】【BZOJ1031】字符加密Cipher
- BZOJ1031: [JSOI2007]字符加密Cipher
- bzoj1031【JSOI2007】字符加密Cipher
- 【bzoj1031】[JSOI2007]字符加密Cipher
- RabbitMq的整理 exchange、route、queue关系
- 题目列表
- Spring MVC如何接收浏览器传递来的请求参数--request--形参--实体类封装(类比Struts2模型驱动)
- matplotlib绘图实例:pyplot、pylab模块及作图参数
- Failed to load or instantiate TagLibraryValidator class
- bzoj1031[JSOI2007]字符加密Cipher(拆环变链,利用sa数组)
- 关于VS2015中strncap和strcpy函数的问题及解决办法
- Gson,fastjson,jackson效率测试程序
- Linux下已有python2.* 安装pyhton3.6.1与pip3
- Spark之 map和flatMap
- 蓝屏dump分析教程,附分析工具WinDbg(x86 x64)6.12.0002.633下载
- 关于 MVVM 和 ReactiveCocoa
- 维纳滤波LMS matlab
- 常见的状态码