题意:
给出一个字符串,问这个字符串经过移动后的字典序最小的字符串的首字符位置和字典序最大的字符串的首字符的位置,和能出现多少次最小字典序的字符串和最大字典序的字符串
解析:
能出现多少次就是求整个字符串能出现几次循环
然后就是最大最小表示法。。有点厉害。。。
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int nex[maxn]; int get_min(char *s)
{
int n = strlen(s);
int i=, j = , k = , t;
while(i < n && j < n && k < n)
{
t = s[(i+k) % n] - s[(j+k) % n];
if(!t) k++;
else
{
if(t > ) i += k+;
else j += k+;
if(i == j)
j++;
k = ;
}
}
return min(i, j);
} int get_max(char *s)
{
int n = strlen(s);
int i=, j = , k= , t;
while(i < n && j < n && k < n)
{
t = s[(i+k) % n] - s[(j+k) % n];
if(!t) k++;
else
{
if(t > ) j += k+;
else i += k+;
if(i == j)
j++;
k = ;
}
}
return min(i, j);
} void get_next(char *s)
{
int len = strlen(s);
int j, k;
j = , k = -, nex[] = -;
while(j < len)
{
if(k == - || s[j] == s[k])
nex[++j] = ++k;
else
k = nex[k];
}
} char s[maxn];
int main()
{
while(~rs(s))
{
int len = strlen(s);
int a = get_min(s);
int b = get_max(s);
int c;
get_next(s);
if(len % (len - nex[len]) == )
c = len / (len - nex[len]);
else
c = ;
cout<< a+ << " " << c << " " << b+ << " " << c <<endl; } return ;
}