• 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
  • 相关阅读:
    国内好用的maven仓库,添加到本地nexus中
    02 介绍
    11 jsp脚本调用java代码
    12 jsp page 指令
    14 javaBean 组件
    13 jsp include
    01 Servlet & Jsp 技术概述
    pl/sql 实例精解 05
    pl/sql 实例精解 06
    pl/sql 实例精解 08
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3898148.html
Copyright © 2020-2023  润新知