Codeforces 259 B

题目链接:http://codeforces.com/contest/454/problem/B

解题报告:太渣了,这个模拟题最后跑大数据的时候挂了,最后还花了很久才过,用的最笨的方法,直接模拟,代码繁琐又长,代码还改了很久。

我用队列直接暴力模拟,当队尾的元素小于队首时,就把队尾的元素移到队首去,要特判一下是不是只有一个元素,然后还要注意全是一样的,如果不判断会陷入死循环,

然后这样模拟之后再判断现在的序列是不是一个非递减的序列。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<deque>
 6 using namespace std;
 7 const int maxn = 100000+5;
 8 int A[maxn];
 9 deque<int> que;
10 int main()
11 {
12     int n;
13     while(scanf("%d",&n)!=EOF)
14     {
15         
16         que.clear();
17         int d;
18         for(int i = 1;i <= n;++i)
19         {
20             scanf("%d",&d);
21             que.push_back(d);
22         }
23         if(n == 1)
24         {
25             puts("0");
26             continue;
27         }
28         int ci = n;
29         while(*(que.end()-1) <= *que.begin() && ci > 0)
30         {
31             ci--;
32             int temp = *(que.end() - 1);
33             que.pop_back();
34             que.push_front(temp);
35         }
36         int t = *que.begin(),flag = 0,tt = *que.begin();
37         while(!que.empty())
38         {
39             if(t > *que.begin())
40             {
41                 flag = -1;
42                 break;
43             }
44             t = *que.begin();
45             if(t != tt) flag = 1;
46             que.pop_front();
47         }
48         if(flag == -1 || flag == 0) printf("%d
",flag);
49         else printf("%d
",n - ci);
50     }
51     return 0;
52 }
View Code
原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3898148.html