码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces——Little Pony and Sort by Shift

时间:2014-08-02 09:53:43      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   div   amp   

 1 /*
 2  题目大意:给你一个序列,不断地将最后边的数值移动到最前边,问最少经过多少次可以变成一个单调递增的序列! 
 3  如果不能则输出-1。 
 4  如果该序列按照不断从后向前移动排序成功,那么该序列要么只有一个单调递增的序列,
 5  或者有两段单调递增的序列(1..k 和 k+1..n)并且 (k+1...n)中的最大值num[n]<=(1...k)中的最小值num[1] 
 6 */
 7 #include<iostream>
 8 #include<cstdio>
 9 using namespace std;
10 int a[100005];
11 int main(){
12    int n;
13    while(scanf("%d", &n)!=EOF){
14        int cnt=0;
15        int cur=0, nt, place=0;
16        for(int i=1; i<=n; ++i){
17            scanf("%d", &nt);
18            a[i]=nt;
19            if(nt<cur){
20               ++cnt;
21               place = i;
22            }
23            cur=nt;
24        }
25        if(cnt==0)
26           printf("0\n"); 
27        else if(cnt>1)
28           printf("-1\n");
29        else{
30           if(a[n] > a[1])
31              printf("-1\n");
32           else printf("%d\n", n-place+1);
33        }
34    }
35    return 0;
36 } 

 

codeforces——Little Pony and Sort by Shift,布布扣,bubuko.com

codeforces——Little Pony and Sort by Shift

标签:style   blog   color   os   io   for   div   amp   

原文地址:http://www.cnblogs.com/hujunzheng/p/3886453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!