hzwer:"输出最小表示"

感觉就是kmp的思想呢?

 

 1 /**************************************************************
 2     Problem: 2882
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:492 ms
 7     Memory:1976 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12  
13 using namespace std;
14 const int N = 300005;
15  
16 int n;
17 int a[N];
18  
19 int work() {
20     int i = 0, j = 1, k = 0, tmp;
21     while (i < n && j < n && k < n) {
22         tmp = a[(i + k) % n] - a[(j + k) % n];
23         if (!tmp) ++k;
24         else {
25             if (tmp > 0) i += k + 1;
26             else j += k + 1;
27             if (i == j) ++i;
28             k = 0;
29         }
30     }
31     return min(i, j);
32 }
33  
34 int main() {
35     int i, st;
36     scanf("%d", &n);
37     for (i = 0; i < n; ++i)
38         scanf("%d", a + i);
39     st = work();
40     printf("%d", a[st % n]);
41     for (i = 1; i < n; ++i)
42         printf(" %d", a[(st + i) % n]);
43     return 0;
44 }
View Code

 

posted on 2014-12-16 18:35  Xs酱~  阅读(397)  评论(0编辑  收藏  举报