| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
暴力可以過,1797ms,但是注意幾個优化1,膜运算尽量少用,最好都提前算出来
2,碰到两个相等的时候直接退出,因为这个时候字符串是周期的
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
char s[10010];
int l;
int cmp(int a, int b){
for(int i = 0; i < l; i++){
int cha = s[(a+i)%l] - s[(b+i)%l];
if(cha > 0) return 1;
if(cha < 0) return -1;
}
return 0;
}
int main() {
int n;
scanf("%d", &n);
while(n--){
scanf("%s", s);
l = strlen(s);
int mn = 0;
for(int i = 1; i < l; i++){
int res = cmp(mn, i);
if(res > 0) mn = i;
if(res == 0) break;
}
printf("%d\n", mn+1);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator