Codeforces 259 B - Little Pony and Sort by Shift
题目链接: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的更多相关文章
- codeforces 454B. Little Pony and Sort by Shift 解题报告
题目链接:http://codeforces.com/problemset/problem/454/B 题目意思:给出一个序列你 a1, a2, ..., an. 问每次操作只能通过将最后一个数拿出来 ...
- codeforces——Little Pony and Sort by Shift
/* 题目大意:给你一个序列,不断地将最后边的数值移动到最前边,问最少经过多少次可以变成一个单调递增的序列! 如果不能则输出-1. 如果该序列按照不断从后向前移动排序成功,那么该序列要么只有一个单调递 ...
- Codeforces #259 Div.2
A. Little Pony and Crystal Mine 模拟题. 用矩阵直接构造或者直接根据关系输出 B. Little Pony and Sort by Shift 模拟题. 通过提供的操作 ...
- Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)
题目链接:http://codeforces.com/contest/451/problem/B --------------------------------------------------- ...
- Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...
- codeforces 652D D. Nested Segments(离散化+sort+树状数组)
题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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 ...
- codeforces 454 D. Little Pony and Harmony Chest(状压dp)
题目链接:http://codeforces.com/contest/454/problem/D 题意:给定一个序列a, 求一序列b,要求∑|ai−bi|最小.并且b中任意两数的最大公约数为1. 题解 ...
- codeforces 454 E. Little Pony and Summer Sun Celebration(构造+思维)
题目链接:http://codeforces.com/contest/454/problem/E 题意:给出n个点和m条边,要求每一个点要走指定的奇数次或者是偶数次. 构造出一种走法. 题解:可能一开 ...
随机推荐
- shell操作mysql之增删改查
假设mysql用户名root 密码123456,新建测试数据表utable 脚本如下: #!/bin/bash#mysqlop.shmysql="/app/local/mysql/bin/m ...
- MySQL外键使用需要注意的几点
最近刚刚接触MySQL,在建立表示遇到了一些问题,总是提示错误代码:150 can't create table ...,所以就到网上搜索了一下发现还有以下几点需要注意的: [CONSTRAINT [ ...
- Nginx+PHP-fpm高负载优化及压力测试方法
Nginx+PHP-fpm组合,以内存占用小,负载能力强壮的特点,成为小内存VPS建站的首选组合.我们一起来探讨一下nginx+php-fpm高负载的优化方法. 先来看看nginx配置参数的优化.ng ...
- cmake 静态调用 c++ dll 的类的一个例子(Clion IDE)[更新1:增加1.模版的应用,2.ma 的算法]
CMakeLists.txt project(aaa) add_library(aaa SHARED aaa.cpp) add_executable(bbb bbb.cpp) target_link_ ...
- Embedding Scripts
Mono http://www.mono-project.com/docs/advanced/embedding/ http://www.mono-project.com/docs/advanced/ ...
- $this->display输出模板
1.public function index(){ $this->display() } // 默认输出的是index.html模板 2.public function index(){ $t ...
- jquermobile 安装
代码 <script src="../Public/js/jquery-1.11.1.min.js"></script> <script src=&q ...
- js基本数据类型和typeof
JavaScript数据类型是非常简洁的,它只定义了6中基本数据类型 null:空.无.表示不存在,当为对象的属性赋值为null,表示删除该属性 undefined:未定义.当声明变量却没有赋值时会显 ...
- autofac Adding services after container has been built
http://stackoverflow.com/questions/6173566/run-time-registration-with-autofac Yes you can, using the ...
- oracle 的wm_concat函数使用
转载自:http://blog.itpub.net/post/42245/522757 首先让我们来看看这个神奇的函数wm_concat(列名),该函数可以把列值以","号分隔起来 ...