题目链接: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. w3m常用快捷键

    H    显示帮助 q    退出,会有提示的 j,k,l,h  移动光标 J/K   向下/向上滚屏 T     打开一个新标签页 Esc-t 打开所有标签页,供你选择,使用jk来上下移动 U    ...

  2. 在C#中使用官方驱动操作MongoDB

    MongoDB的官方驱动下载地址:https://github.com/mongodb/mongo-csharp-driver/releases 目前最新的版本是2.10,支持.NET 4.5以上.由 ...

  3. IBatis学习

    (1)建立 SqlMap.config文件 <?xml version="1.0" encoding="utf-8" ?> <sqlMapCo ...

  4. libuv(不断更新)

    /* * Initialize the uv_async_t handle. A NULL callback is allowed. * * Note that uv_async_init(), un ...

  5. Java web 使用页面压缩

    借助类,相关依赖: <!-- https://mvnrepository.com/artifact/net.sourceforge.pjl-comp-filter/pjl-comp-filter ...

  6. td:first-child 伪类 匹配第一个 匹配第一个 <td> 元素

    css代码: td:first-child{border-right: 1px solid #d9dbdd; } 备注:在下面的例子中,选择器匹配作为任何元素的第一个子元素的 p 元素: 链接:htt ...

  7. JVM 小结

    1.jvm虚拟机的种类及特点 Sun Classic:解释和编译不能协调使用:使用基于句柄的对象查找. Exact VM:解释和编译能协调使用:采用准确式内存管理:可以知道内存中某个位置的数据是什么类 ...

  8. VS2015 推荐插件

    VS2015 推荐插件 //////////////////////////////////////////////////////////////////////////////////////// ...

  9. Saltstack常用模块及API

    Saltstack提供了非常丰富的功能模块,涉及操作系统的基础功能.常用工具支持等,更多模块信息可以查看官网模块介绍.也可以通过sys模块列出当前版本支持的模块. salt '*' sys.list_ ...

  10. Java调试

    线上load高的问题排查步骤是: 先用top找到耗资源的进程 ps+grep找到对应的java进程/线程 jstack分析哪些线程阻塞了,阻塞在哪里 jstat看看FullGC频率 jmap看看有没有 ...