bzoj2176 Strange string 最小表示法
来源:互联网 发布:ios淘宝hd历史版本 编辑:程序博客网 时间:2024/06/05 14:36
题意:给出一个字符串s(n<=10000000),求他的最小表示法
一开始发现SA或者SAM可以做好像,然而n<=1000w,word哥还是搞最小表示法把。。
最小表示法其实就是一个字符串的最小字典序循环同构的串。
可能你还是很懵比,好举个例子。
设S=bcda,那么S的循环同构串就是cdab,dabc,abdc,他的最小表示法就是abdc.
其实就是要找的一个i的位置,从这个i开始把S断掉,然后输出的就是abdc。
怎么找这个i呢?
我们可以先来想想暴力打法(dalao请跳过)
一开始暴力肯定就是双指针嘛,设i=0,j=1,
然后就有:
i=0,j=1;
while (i
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#define N 10000005using namespace std;int n;unsigned char s[N*2];int main(){ freopen("2176.in","r",stdin);//freopen("test.out","w",stdout); scanf("%d",&n); scanf("%s",s+1); for (int i=n+1;i<=n*2;i++) s[i]=s[i-n]; int i=1,j=2; while (i<n&&j<n) { int k=0; while (s[i+k]==s[j+k]&&k<n) k++; if (k==n) break; if (s[i+k]<s[j+k]) j=max(j+k+1,i+1); else i=max(i+k+1,j+1); } i=min(i,j); for (int k=1;k<=n;k++) putchar(s[k+i-1]); return 0;}
0 0
- bzoj2176 Strange string 最小表示法
- 【bzoj2176】Strange string
- bzoj2176: Strange string
- BZOJ 2176 Strange string 最小表示法
- BZOJ 2176: Strange string 最小表示法
- BZOJ 2176: Strange string【字符串最小表示法
- bzoj 2176: Strange string 字符串最小表示法
- Ural 1423. String Tale 最小表示法
- String Problem-kmp+最小表示法
- HDOJ3374 String Problem 【KMP】+【最小表示法】
- hdu3374 String Problem(KMP+最小表示法)
- HDU3374 String Problem(KMP + 最小表示法)
- String Problem (最小表示法+KMP)
- HDU 3374 String Problem(最小最大表示法+KMP)
- HDU3374(String Problem)字符串-最小表示法+KMP
- String Problem + 最大(最小)表示法+KMP
- HDU 3374 String Problem KMP-最小最大表示法
- HDU 3374String Problem(最大最小表示法+KMP)
- html
- html 20170211
- hdu-2553 N皇后问题
- Scala 函数式编程进阶 最重要的内容
- Vue.js 和 MVVM 小细节
- bzoj2176 Strange string 最小表示法
- ahk自动上传文件的脚本实例
- 面试题--死锁
- oracle中all,any的区别使用
- 如何在日常交流中选择合适的投资人?
- 1025 选菜(codevs)
- html5 移动端触发的基本事件
- java连接sql server
- 数据结构之用递归和非递归方法计算斐波那契数列的第n项