BZOJ 2176: Strange string 最小表示法
来源:互联网 发布:赌球外围软件 编辑:程序博客网 时间:2024/06/05 16:18
2176: Strange string
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 375 Solved: 153
[Submit][Status][Discuss]
Description
给定一个字符串S = {S1, S2, S3 … Sn}, 如果在串SS中, 子串T(|T| = n)为所有长度为n的SS的字串中最小的(字符串的比较), 则称T为”奇怪的字串”. 你的任务就是找出这个字符串.
Input
读入两行, 第一行为n, 第二行为字符串S.
Output
将”奇怪的字串” T输出输入样例
Sample Input
10
asdfasdfas
asdfasdfas
Sample Output
asasdfasdf
HINT
数据范围
对于100%的数据, 保证n≤10000000;
给定的字符串中的字符保证在#33 ~ #254之间.
最小表示法,加unsigned char
空间开二倍比%运算不知快到哪里去。。
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<map>#include<set>using namespace std;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=10*x+ch-'0';ch=getchar();}return x*f;}inline void print(int x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=10000100;unsigned char s[N<<1];int main(){int n=read();scanf("%s",s+1);for(int i=1;i<=n;i++)s[i+n]=s[i];int k=0,i=1,j=2;while(k<=n&&j<=n&&i<=n){int t=s[i+k]-s[j+k];if(!t)k++;else{if(t<0)j+=k+1;else i+=k+1;k=0;if(i==j)i++;}}int ans=min(i,j);for(int i=0;i<n;++i)putchar(s[ans+i]);puts("");return 0;}/*10asdfasdfasasasdfasdf*/
阅读全文
0 0
- BZOJ 2176 Strange string 最小表示法
- BZOJ 2176: Strange string 最小表示法
- BZOJ 2176: Strange string【字符串最小表示法
- bzoj 2176: Strange string 字符串最小表示法
- bzoj2176 Strange string 最小表示法
- [BZOJ 2176]Strange string
- bzoj 1398 &&bzoj 2882最小表示法
- bzoj 1398 项链 【最小表示法】
- 【BZOJ 2882】工艺 最小表示法
- BZOJ 2882: 工艺 最小表示法
- [BZOJ]2882 工艺 最小表示法
- bzoj 2882(最小表示法)
- Ural 1423. String Tale 最小表示法
- String Problem-kmp+最小表示法
- HDOJ3374 String Problem 【KMP】+【最小表示法】
- hdu3374 String Problem(KMP+最小表示法)
- HDU3374 String Problem(KMP + 最小表示法)
- String Problem (最小表示法+KMP)
- HDU2089 不要62[数位DP]
- android系统添加内置APP(自带.so)
- 架构师成长之路
- 闲谈:移动端车牌识别技术在行业中的应用
- 几种开源数据库
- BZOJ 2176: Strange string 最小表示法
- PHP 5.3.8 成功连接 SQL Server 2005
- 学习Git(分布式版本控制系统)——基础篇
- 集合及map体系
- Redis高可用架构
- Spring学习(1) IOC的含义,思想以及实现方法。
- Python实现回归树
- POJ-1005
- 数字签名相关概念介绍