一开始没太看懂什么意思,拿笔反复推了一遍才大概知道最大最小表示法是怎么求的,感觉太神奇了...
#include <iostream>
#include <cstdio>
#include <string.h>
#pragma warning ( disable : 4996 )
using namespace std; inline int Max(int a,int b) { return a>b?a:b; }
inline int Min(int a,int b) { return a>b?b:a; }
const int inf = 0x3f3f3f3f;
const int maxn = 1e6+; char str[maxn];
int nxt[maxn];
int len, plen, minpos, maxpos; void getNext()
{
memset( nxt, , sizeof(nxt) );
len = strlen(str); int k = -, j = ;
nxt[j] = -; while ( j < len )
{
if ( k==- || str[j]==str[k] )
{
k++; j++;
nxt[j] = k;
}
else
k = nxt[k];
}
plen = nxt[len];
} void getMin()
{
int tmp, i = , j = , k = ;
while ( i<len && j <len && k <len )
{
tmp = str[(i+k)%len]-str[(j+k)%len];
if(!tmp) k++;
else
{
if(tmp>) i += k+;
else j += k+;
if( i == j ) j++;
k = ;
}
}
minpos = i<j?i+:j+;
} void getMax()
{
int tmp, i = , j = , k = ;
while ( i<len && j<len && k<len )
{
tmp = str[(i+k)%len]-str[(j+k)%len];
if(!tmp) k++;
else
{
if(tmp<) i += k+;
else j += k+;
if( i == j ) j++;
k = ;
}
}
maxpos = i<j?i+:j+;
} int main()
{
while ( ~scanf("%s", str) )
{
getNext();
getMin();
getMax(); int tmp = (len%(len-plen)==)?(len/(len-plen)):;
printf( "%d %d %d %d\n", minpos, tmp, maxpos, tmp );
}
return ;
}