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. Python之路第十一天,高级(3)-Python操作 Memcached、Redis

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  2. 映射 SQL 和 Java 类型

    http://alex2009.blog.51cto.com/749524/272942 AJAX: http://www.w3school.com.cn/jquery/ajax_ajax.asp h ...

  3. 自己封装的一个简易的二维表类SimpleTable

    在QT中,QTableWidget处理二维表格的功能很强大(QTableView更强大),但有时我们只想让它显示少量数据(文字和图片),这时,使用QTableWidget就有点不方便了(个人感觉).所 ...

  4. 在Unicode版Inno Setup中使用ISSkin给安装程序添加皮肤

    原文 http://www.cnblogs.com/2356/archive/2009/10/27/1590565.html 在Unicode版Inno Setup中使用ISSkin给安装程序添加皮肤 ...

  5. linux之SQL语句简明教程---GROUP BY

    我们现在回到函数上.记得我们用 SUM 这个指令来算出所有的 Sales (营业额)吧!如果我们的需求变成是要算出每一间店 (Store_Name) 的营业额 (Sales),那怎么办呢?在这个情况下 ...

  6. UML_组件图

    简介 众所周知,组件图是用来描述系统中的各组件之间的关系.首先我们必须知道组件的定义是什么,然后组件之间有哪些关系.理清楚这些,我们在以后的设计中才能 派上用场.UML语言对组件的定义已发生了巨大变化 ...

  7. N1必备外来语

    201412: キャリア: ノルマ:(normal)定额,劳动基本定额. チーフ: コスト: バンド:[英] band;皮带,腰带:吹奏乐团,轻音乐乐团(演奏者の一団.楽団.楽隊):营居群 [2014 ...

  8. 安装Linux系统到u盘

    第一步:首先插入u盘到电脑主机usb接口处(建议插入到主机箱后置的usb接口).然后打开UltraISO软件,再打开选择须要写入u盘的Ubuntu 10.04或者其它版本号的Linux系统的iso镜像 ...

  9. Reverse Key Indexes反向索引

    Reverse Key Indexes反向索引A reverse key index is a type of B-tree index that physically reverses the by ...

  10. zepto 获取select选中的值

    jQuery中典型的方法: $('option[selected]') 不管用,因为selected并不是CSS标准.   因此,在zepto中想要获取select元素中选中的option,需采取如下 ...