【bzoj2176】Strange string
来源:互联网 发布:js获取post过来的值 编辑:程序博客网 时间:2024/05/16 11:23
Description
给定一个字符串S = {S1, S2, S3 … Sn}, 如果在串SS中, 子串T(|T| = n)为所有长度为n的SS的字串中最小的(字符串的比较), 则称T为”奇怪的字串”. 你的任务就是找出这个字符串.
Input
读入两行, 第一行为n, 第二行为字符串S.
Output
将”奇怪的字串” T输出输入样例
Sample Input
10
asdfasdfas
Sample Output
asasdfasdf
HINT
数据范围
对于100%的数据, 保证n≤10000000;
给定的字符串中的字符保证在#33 ~ #254之间.
题解
最小表示法
http://blog.csdn.net/zy691357966/article/details/39854359
代码
#include<bits/stdc++.h>#define pa pair<int,int>#define ll long long#define inf 10000005using 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>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int n; unsigned char ch[10001000];int Min_Representation(){ int i=1,j=2,k=0; while (i<=n&&j<=n&&k<=n) { int x=(i+k-1)%n+1,y=(j+k-1)%n+1; if (ch[x]==ch[y]) k++; else if (ch[x]>ch[y]) i=i+k+1,k=0; else j=j+k+1,k=0; if (i==j) j++; } return min(i,j);}int main(){ scanf("%d\n",&n); fread(ch+1,1,n,stdin); int ans=Min_Representation(); if (ans==1)fwrite(ch+1,1,n,stdout); else fwrite(ch+ans,1,n-ans+1,stdout),fwrite(ch+1,1,ans-1,stdout); puts(""); 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【字符串最小表示法
- bzoj 2176: Strange string 字符串最小表示法
- Strange Clock
- strange recursion
- Really Strange!!
- Strange Dialog
- Strange Addition
- !! Really Strange !!
- Strange fuction
- Strange Class
- Strange fuction
- strange function
- [poj1740]A New Stone Game
- 一年的美国生活
- java二叉树
- springmvc中一次请求再次深入学习
- Linux 下启动、关闭tomcat 杀掉进程等命令
- 【bzoj2176】Strange string
- HDU5950 Recursive sequence —— 矩阵快速幂
- MongoDB基础篇:MongoDB Shell命令大全
- POJ
- c++文件读写
- # JDK安装及环境配置
- 从零开始学Java
- git warning: LF will be replaced by CRLF in xxxxx 解决办法
- 我等的宏观发展来了,国家级AI