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

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

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

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

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<deque>
using namespace std;
const int maxn = +;
int A[maxn];
deque<int> que;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{ que.clear();
int d;
for(int i = ;i <= n;++i)
{
scanf("%d",&d);
que.push_back(d);
}
if(n == )
{
puts("");
continue;
}
int ci = n;
while(*(que.end()-) <= *que.begin() && ci > )
{
ci--;
int temp = *(que.end() - );
que.pop_back();
que.push_front(temp);
}
int t = *que.begin(),flag = ,tt = *que.begin();
while(!que.empty())
{
if(t > *que.begin())
{
flag = -;
break;
}
t = *que.begin();
if(t != tt) flag = ;
que.pop_front();
}
if(flag == - || flag == ) printf("%d\n",flag);
else printf("%d\n",n - ci);
}
return ;
}

Codeforces 259 B - Little Pony and Sort by Shift的更多相关文章

  1. codeforces 454B. Little Pony and Sort by Shift 解题报告

    题目链接:http://codeforces.com/problemset/problem/454/B 题目意思:给出一个序列你 a1, a2, ..., an. 问每次操作只能通过将最后一个数拿出来 ...

  2. codeforces——Little Pony and Sort by Shift

    /* 题目大意:给你一个序列,不断地将最后边的数值移动到最前边,问最少经过多少次可以变成一个单调递增的序列! 如果不能则输出-1. 如果该序列按照不断从后向前移动排序成功,那么该序列要么只有一个单调递 ...

  3. Codeforces #259 Div.2

    A. Little Pony and Crystal Mine 模拟题. 用矩阵直接构造或者直接根据关系输出 B. Little Pony and Sort by Shift 模拟题. 通过提供的操作 ...

  4. Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

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

  5. Codeforces Round #258 (Div. 2) B. Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...

  6. codeforces 652D D. Nested Segments(离散化+sort+树状数组)

    题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #258 (Div. 2)——B. Sort the Array

    B. Sort the Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. codeforces 454 D. Little Pony and Harmony Chest(状压dp)

    题目链接:http://codeforces.com/contest/454/problem/D 题意:给定一个序列a, 求一序列b,要求∑|ai−bi|最小.并且b中任意两数的最大公约数为1. 题解 ...

  9. codeforces 454 E. Little Pony and Summer Sun Celebration(构造+思维)

    题目链接:http://codeforces.com/contest/454/problem/E 题意:给出n个点和m条边,要求每一个点要走指定的奇数次或者是偶数次. 构造出一种走法. 题解:可能一开 ...

随机推荐

  1. ServiceStack.Text 更快的序列化

    Json.net 是以前最经常用的序列化组件,后来又注意到ServiceStack号称最快的,所以我做了以下测试 1)Json.net using System; using System.Colle ...

  2. socket编程--socket模块介绍

    socket也称作'套接字,用于描述IP地址和端口,是一个通信的终点. socket起源于Unix,而Unix/Linux基本哲学之一就是"一切皆文件",对于文件用[打开][读写] ...

  3. 转:netflix推荐系统竞赛

    原文链接:Netflix recommendations: beyond the 5 stars (Part 1), (Part 2) 原文作者:Xavier Amatriain and Justin ...

  4. HTML学习笔记——frameset和marquee

    1>frameset 效果如百Google度 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  5. 在页面头部<!DOCTYPE html ....> 前面不能有任何输出

    <!-- 这里不能有任何输出,注释也不行 --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  6. Robot Framework--02 菜单栏&工具栏

    转自:http://blog.csdn.net/tulituqi/article/details/7584795 我把RIDE的界面大致分了四个区域:菜单栏.工具栏.案例及资源区.工作区,如下图 菜单 ...

  7. VS代码段扩展Snippet Designer is a Visual Studio plug in which allows you to create and search for snippets inside the IDE

    Snippet Designer is a Visual Studio plug in which allows you to create and search for snippets insid ...

  8. 详细整合教程(Spring+SpringMVC+MyBatis)

    详细整合教程(Spring+SpringMVC+MyBatis) http://blog.csdn.net/gebitan505/article/details/44455235/

  9. maven 入门

    Apache Maven 入门篇 ( 上 ) 作者:George Ma 写这个 maven 的入门篇是因为之前在一个开发者会的动手实验中发现挺多人对于 maven 不是那么了解,所以就有了这个想法.这 ...

  10. servlet生命周期与工作原理

    →   Jsp的本质是Servlet,Servlet是服务器端的小程序,运行在服务器,用于处理及响应客户端的请求. Servlet和JSP的区别: servlet是特殊的Java类,必须继承HttpS ...