【HDOJ】1908 Double Queue
双端队列+二分。
#include <cstdio> #define MAXN 1000005 typedef struct {
int id;
int p;
} node_st; node_st que[MAXN];
int rear = ,front = ; void Insert(int id, int p) {
int l = front, r = rear, mid; while ( l <= r) {
mid = (l+r)>>;
if (que[mid].p == p)
break;
if (que[mid].p < p)
l = mid+;
else
r = mid - ;
}
while (mid<rear && que[mid].p <= p)
++mid;
for (int i=rear-; i>=mid; --i)
que[i+] = que[i];
que[mid].id = id;
que[mid].p = p;
rear++;
} int main() {
int c, id, p; while (scanf("%d", &c)!=EOF && c) {
if (c == ) {
scanf("%d %d", &id, &p);
Insert(id, p);
} else {
if (rear == front)
printf("0\n");
else {
if (c == )
printf("%d\n", que[--rear].id);
else
printf("%d\n", que[front++].id);
}
}
} return ;
}
【HDOJ】1908 Double Queue的更多相关文章
- hdu 1908 Double Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...
- 【DataStructure】One of queue usage: Simulation System
Statements: This blog was written by me, but most of content is quoted from book[Data Structure wit ...
- 【HDOJ】1297 Children’s Queue
递推,最近发现自己做递推的题总是没有思路.下周多练习.对于f(n)可以在第n个位置为男生,此时共有f(n-1)种情况:若在第n个位置为女生,因此第n-1个位置也必须为女生.此时有两种情况,一种情况是在 ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】4579 Random Walk
1. 题目描述一个人沿着一条长度为n个链行走,给出了每秒钟由i到j的概率($i,j \in [1,n]$).求从1开始走到n个时间的期望. 2. 基本思路显然是个DP.公式推导也相当容易.不妨设$dp ...
- 【HDOJ】4418 Time travel
1. 题目描述K沿着$0,1,2,\cdots,n-1,n-2,n-3,\cdots,1,$的循环节不断地访问$[0, n-1]$个时光结点.某时刻,时光机故障,这导致K必须持续访问时间结点.故障发生 ...
- 【HDOJ】4347 The Closest M Points
居然是KD解. /* 4347 */ #include <iostream> #include <sstream> #include <string> #inclu ...
随机推荐
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Android pulltorefresh引用遇到的一个问题
今天在使用pulltorefresh插件的时候遇到了一个让人头疼的问题,在Eclipse中导入要用到的library项目,然后新建一个项目引入Library,显示的是引入成功,如图 而且project ...
- 关于ASP.Net中路径的问题
比如你的工程是Webapplication1(url是:http://localhost/webapplication1/webform1.aspx) Request.ApplicationPath ...
- ubuntu15.10升级时校验和不符的解决方法
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园: 追风917 # 错误 # 原因分析 进入/var/lib/apt/lists/partial看下吧: 看到了吧 ...
- Android eclipse - aapt.exe has stopped working.
今天在修改Android的布局文件的时候,发现每保存一次,就提示: aapt.exe has stopped working(appt.exe已停止工作).很是郁闷,当时Android控制台已经提示错 ...
- [转载]Oracle基础知识
一.oracle安装过程略 二.sys用户和system用户 (1)sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限 默认密码是change_onins ...
- linunx 定位最耗资源的进程
[oracle@topbox bdump]$ ps -ef|grep “(LOCAL=NO)”|sort -rn -k 8,8|head -10oracle 9402 1 67 09:1 ...
- [Twisted] deferred
Twisted提供一个优雅的实现(Deferred)来管理回调函数. Deferred Object 的结构 Deferred Object包含两个回调函数列表.一个用来保存成功的回调函数,另一个用来 ...
- help python(查看模块帮助文档)
查看模块帮助文档: help(len) -- docs for the built in len function (note here you type "len" not &q ...
- swift 遍历
最简单的一个遍历数组 for 随便起个名字 in 升级 上面的看不懂的话,这个应该会简单点 import UIKit let interestingNumbers = [ ,,,,,], ,,,,,] ...