BZOJ 2457 双端队列
Input第一行包含一个整数 N ,表示整数的个数。接下来的 N 行每行包含一个整数 Di ,其中 Di 表示所需处理的整数。Output
Sample Input
Sample Output
2
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<vector>
#include<queue>
//#include<stack>
//#include<map>
#define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
#define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
#define Ii inline int
#define Iv inline void
#define Il inline long long
#define Ib inline bool
#define INF 0x7ffffff
#define re register
#define ll long long
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define Fill(a,b) memset((a),(b),sizeof((a)))
#define D_e_Line printf("\n-------------\n");
#define D_e(x) printf("\n______%d_______\n",x)
#define Pause system("pause")
using namespace std;
const int N=;
Ii read(){
int s=,f=;char c;
for(c=getchar();c>''||c<'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
template<class Tp>Iv print(Tp x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
#define down 0
#define up 1
struct node{
int w,id;
bool operator< (const node a)const{
if(w!=a.w)return w<a.w;
return id<a.id;
}
}a[N<<];
int mx[N],mi[N];
int main(){
int n=read(),cnt=,flag=up,tmp=INF,ans=;
R(i,,n)
a[i]=(node){read(),i};
sort(a+,a+n+);
R(i,,n)
if(i==||a[i].w!=a[i-].w)
mx[cnt]=a[i-].id,
mi[++cnt]=a[i].id;
mx[cnt]=a[n].id;
R(i,,cnt){
if(flag==down){
if(tmp>mx[i])
tmp=mi[i];
else
tmp=mx[i],flag=up;
}
else if(flag==up){
if(tmp<mi[i])
tmp=mx[i];
else
flag=down,tmp=mi[i],++ans;
}
}
print(ans);
return ;
}
BZOJ 2457 双端队列的更多相关文章
- BZOJ 2457 - 双端队列 - [思维题]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2457 Description Sherry现在碰到了一个棘手的问题,有N个整数需要排序. ...
- BZOJ 2457 双端队列(思维
2457: [BeiJing2011]双端队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 582 Solved: 253[Submit][Sta ...
- 【贪心】Bzoj 2457:[BeiJing2011]双端队列
2457: [BeiJing2011]双端队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 209 Solved: 95[Submit][Stat ...
- BZOJ 2457 [BeiJing2011] 双端队列
2457: [BeiJing2011]双端队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 340 Solved: 167[Submit][Sta ...
- bzoj 2457 [BeiJing2011]双端队列 模拟+贪心
[BeiJing2011]双端队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 457 Solved: 203[Submit][Status][D ...
- 2457: [BeiJing2011]双端队列
2457: [BeiJing2011]双端队列 链接 很奇妙的转化. 题目要求最后的所有序列也是有序的,所以可以求出最后的序列(即排序后的序列),然后分成许多份,要求每一份都是一个双端序列,求最少分成 ...
- BZOJ2457 BeiJing2011 双端队列
[问题描述] Sherry现在碰到了一个棘手的问题,有N个整数需要排序. Sherry手头能用的工具就是若干个双端队列. 她需要依次处理这N个数,对于每个数,Sherry能做以下两件事 ...
- bzoj2457 双端队列
虽然分类在数据结构里,但是实际上是个贪心题...... 我自己一开始想到了一个错误的贪心.后来发现对于相等值的处理不行. 有个很神的转化,就是把排好序的队列以及对应的原下标都给搞出来. 然后考虑其中一 ...
- lintcode二叉树的锯齿形层次遍历 (双端队列)
题目链接: http://www.lintcode.com/zh-cn/problem/binary-tree-zigzag-level-order-traversal/ 二叉树的锯齿形层次遍历 给出 ...
随机推荐
- [C++] Pure Virtual Function and Abstract Class
Pure Virtual Function Abstract Class
- [Training Video - 4] [Groovy] Initializing log inside class with constructor
TestService s = new TestService(log,context,testRunner) s.xyz() class TestService{ def log def conte ...
- .net正则查询
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- Memcached在Windows下的配置和使用(转)
出处:http://www.cnblogs.com/sunniest/p/4154209.html Memcached学习笔记---- 安装和配置 首先,下载Memcached相关文件. 打开控制台, ...
- iOS开发--使用lipo命令制作模拟器与真机通用静态库
通常在项目中使用静态库的时候都会有两个版本,一个用于模拟器,一个用于真机,因为Mac和iPhone的CPU不同,才造成了这种情况. 为了模拟器与真机之间切换调试的方便,制作通用版本非常有必要. 现在有 ...
- WinAPI 字符及字符串函数(10): lstrcpy - 复制字符串
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...
- ASP.NET MVC 缓存页面(方法)
- WinForm中Button的使用
自定义样式 先要清除系统风格影响:this.FlatStyle = FlatStyle.Flat; FlatStyle.Flat FlatStyle.System FlatStyle.Standard ...
- OI题目类型总结整理
## 本蒟蒻的小整理qwq--持续更新(咕咕咕) 数据结构 数据结构 知识点梳理 数据结构--线段树 推荐yyb dalao的总结--戳我 以后维护线段树还是把l,r写到struct里面吧,也别写le ...
- vue和jQuery的区别
从jquery到vue或者说是到mvvm的转变是一个思想的转变,是将原有的直接操作dom的思想转变到操作数据上去 vue和jquey对比 jQuery是使用选择器($)选取DOM对象,对其进行赋值.取 ...