| ||||||||||
| 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 | |||||||||
最小表示法 iostream 开加速 wa// WA
#include <iostream>
using namespace std;
int main(){
int t; cin >> t; while(t--){
ios::sync_with_stdio(false); cin.tie(0);
string s; cin >> s;
int i = 0, j = 1, k = 0, n = s.length();
s += s;
while (i < n && j < n && k < n){
if (i == j) j++;
if (s[i + k] == s[j + k]) ++k;
else s[i + k] > s[j + k] ? i += k + 1 : j += k + 1, k = 0;
}
cout << i + 1 << endl;
}
return 0;
}
// AC
#include <iostream>
using namespace std;
int main(){
int t; cin >> t; while(t--){
string s; cin >> s;
int i = 0, j = 1, k = 0, n = s.length();
s += s;
while (i < n && j < n && k < n){
if (i == j) j++;
if (s[i + k] == s[j + k]) ++k;
else s[i + k] > s[j + k] ? i += k + 1 : j += k + 1, k = 0;
}
cout << i + 1 << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator