2013-08-08

POJ 3481  Double Queue

这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是因为它又可能删除优先权最大的,又可能删除优先权最小的,所以当输入为2或者3的时候没办法判断是不是没有顾客了。通过这道题发觉map的其他用法真的是一点不会。所以看了别人的代码用了两种方法试着敲一下,写这个随笔是博客的第一篇文章,内容虽然这么水,但是的确是我之前掌握不好的部分,本菜鸟今天比赛之后受刺激了突然茅塞顿开,决定开此博客记录我的成长,就算小小的收获也晒出来吧,可能我之前缺乏的就是承认自己不会的本来就是很简单的东西的勇气,但愿若干年后我能发现自己坚持了好久。

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
struct node
{
int num,v;
node(){};
node(int a,int b):num(a),v(b){}
friend bool operator<(node a,node b){
return a.v<b.v;
}
};
set<node> st;
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
if(n==)
{
int a,b;
scanf("%d %d",&a,&b);
st.insert(node(a,b));
}
if(n==)
{
if(st.size()==) puts("");
else
{
set<node>::iterator it=st.end();
it--;
printf("%d\n",(*it).num);
st.erase(it);
}
}
if(n==)
{
if(st.size()==) puts("");
else
{
set<node>::iterator it=st.begin();
printf("%d\n",(*it).num);
st.erase(it);
}
}
}
return ;
}

set版本

#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
map<int,int>mp;
int main()
{
int n;
mp.clear();
while()
{
scanf("%d",&n);
if(!n) break;
if(n==)
{
int a,b;
scanf("%d %d",&a,&b);
mp[b]=a;
}
if(n==)
{
if(mp.size()==) puts("");
else
{
map<int,int>::iterator it=mp.end();
it--;
printf("%d\n",it->second);
mp.erase(it);
}
}
if(n==)
{
if(mp.size()==) puts("");
else
{
map<int,int>::iterator it=mp.begin();
printf("%d\n",it->second);
mp.erase(it);
}
}
}
return ;
}

map版本

POJ 3481 Double Queue STLmap和set新学到的一点用法的更多相关文章

  1. POJ 3481 Double Queue(Treap模板题)

    Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15786   Accepted: 6998 Des ...

  2. POJ 3481 Double Queue(STL)

    题意  模拟银行的排队系统  有三种操作  1-加入优先级为p 编号为k的人到队列  2-服务当前优先级最大的   3-服务当前优先级最小的  0-退出系统 能够用stl中的map   由于map本身 ...

  3. POJ 3481 Double Queue(set实现)

    Double Queue The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Buchares ...

  4. POJ 3481 Double Queue

    平衡树.. 熟悉些fhq-Treap,为啥我在poj读入优化不能用啊 #include <iostream> #include <cstdio> #include <ct ...

  5. POJ 3481 Double Queue (treap模板)

    Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest ...

  6. poj 3841 Double Queue (AVL树入门)

    /****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...

  7. hdu 1908 Double Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...

  8. 【Map】Double Queue

    Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13258   Accepted: 5974 Des ...

  9. poj 2259 Team Queue

    Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1092 Descri ...

随机推荐

  1. Nginx学习之三-ngx_http_request_t结构体

    ngx_http_request_s是nginx中非常重要的一个结构体,贯穿于htpp请求处理的整个过程中. 下面解释了ngx_http_request_s结构体中与HTTP框架相关的重要的成员变量. ...

  2. XML的DTD约束

    DTD约束:DTD的声明和引用 1.内部DTD文档 <!DOCTYPE 根元素 [定义内容]> 2.外部DTD文档 <!DOCTYPE 根元素 SYSTEM "DTD文件路 ...

  3. instsrv.exe下载和使用方法(微软Windows Server 2003 Resource Kit Tools工具中的一个)

    instsrv.exe是微软Windows Server 2003 Resource Kit Tools工具中的一个. Windows Server 2003 Resource Kit Tools是一 ...

  4. jquery 中 (function( window, undefined ) {})(window)写法详解(转)

    最常见的闭包 (Closure) 范式大家都很熟悉了: 123 (function() {// ...})(); 很简单,大家都在用.但是,我们需要了解更多.首先,闭包是一个匿名函数 (Anonymo ...

  5. ZZ的计算器

    Problem Description ZZ自从上大学以来,脑容量就是以SB计算的,这个吃货竟然连算术运算也不会了,可是当今的计算机可是非常强大的,作为ACMer, 几个简单的算术又算得了什么呢?可是 ...

  6. 1 & 167. Two Sum I & II ( Input array is sorted )

    Input array is sorted: Use binary search or two pointers Unsorted: Use hash map, key = target - a[i] ...

  7. flume【源码分析】分析Flume的拦截器

    h2 { color: #fff; background-color: #7CCD7C; padding: 3px; margin: 10px 0px } h3 { color: #fff; back ...

  8. 关于VMware导入Linux VM找不到网卡的问题

    今天遇到一个问题:由于虚拟机升级,导致以前的Linux VM(CentoS 6.7)在新的VMware里面打开,系统提示找不到网卡的问题,在网上找了好多解决办法,基本上都是一样的答案. 与网卡有关的几 ...

  9. apache端口被占用

      1.80端口被占用,先去服务里将IIS关闭掉,然后重启apache,如果还是继续弹窗the requested operation has failed...需要去Internet信息服务里面停止 ...

  10. IOS中的几中观察监听模式

    本文介绍Objective C中实现观察者模式(也被称为广播者/监听者.发布/注册或者通知)的五种方法以及每种方法的价值所在. 该文章将包括: 1 手动广播者和监听者(Broadcaster and ...