题目链接: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. 将maven工程转成dynamic web project

    http://blog.csdn.net/remote_roamer/article/details/51724378 做到最后一步就不行鸟,没有plugin........

  2. SSH和SSM项目的打通各个页面的方式

    SSH项目: 这里采用的action的形式: 即在表现层为页面在action中配置一个返回值,然后在Struts.xml的配置文件中进行配置. SSM项目中,SpringMVC中利用注解来配置每个页面 ...

  3. BZOJ4004: [JLOI2015]装备购买

    总之就是线性基那一套贪心理论直接做就好了. 然而加强数据后很卡精度的样子. 于是重点在于这个特技:在整数模意义下搞. #include<cstdio> #include<algori ...

  4. 在Linux下安装和使用MySQL

    [简 介] 想使用Linux已经很长时间了,由于没有硬性任务一直也没有系统学习,近日由于工作需要必须使用Linux下的MySQL.本以为有Windows下使用SQL Server的经验,觉得在Linu ...

  5. nginx主备配置

    添加配置: proxy_next_upstream error timeout invalid_header http_500 http_503 http_502; upstream http.wea ...

  6. 天行API服务器地址申请

    http://www.tianapi.com/ http://www.huceo.com/post/383.html

  7. 爬虫3 html解析器 html_parser.py

    #coding:utf8 import urlparse from bs4 import BeautifulSoup import re __author__ = 'wang' class HtmlP ...

  8. Java导包——import语句

    使用语句import org.common.demo01.Demo: 或者import org.common.demo01.*: 如果一个类声明为public class,则文件名称必须与类名称一致, ...

  9. C++ 内存管理与堆栈

    /*内存管理与堆栈: * # 一个由C/C++编译的程序占用的内存分为以下几个部分 * 1.栈区:由编译器自动分配释放,数据先进后出 * 2.堆区:由程序员手动分配释放,数据先进先出, * new 和 ...

  10. Senparc.Weixin.MP.Sample 配置redis服务器密码

    redis.windows-service.conf中加  requirepass 你的密码 <!-- Cache.Redis连接配置 --> <add key="Cach ...