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. java学习一目了然——异常必知

    java学习一目了然--异常必知 我们只要学java,异常肯定非常熟悉,该抛的时候抛一下就行.但是这其中还有点小细节需要注意.就用这个小短篇来说一下异常处理中的小细节吧. 异常处理 RuntimeEx ...

  2. Leetcode 171 Excel Sheet Column Number python

    题目: Given a column title as appear in an Excel sheet, return its corresponding column number. For ex ...

  3. Leetcode 283 Move Zeroes python

    题目: Given an array nums, write a function to move all 0's to the end of it while maintaining the rel ...

  4. Demo+在Linux下运行(CentOS7+dotnetcore sdk)

    来份ASP.NET Core尝尝 0x01.前言 学习ASP.NET Core也有一段时间了,虽说很多内容知识点还是处于一知半解的状态,但是基本的,还是 略懂一二.如果有错误,还望见谅. 本文还是和之 ...

  5. Ubuntu安装与初始配置

    转载请注明作者:梦里风林 更多文章查看我的个人站: ahangchen.site 适用于Ubuntu版本 14.04/16.04LTS 64位 先上图 双系统安装 划分空闲磁盘,U盘安装ubuntu ...

  6. MYSQL 的 6 个返回时间日期函数

    方法1. curdate(),curtime(),now() 方法2. utc_date(),utc_time(),utc_datetime(); 可以看到utc时间相比东西八区要小8小时 注意. 返 ...

  7. Oracle EBS-SQL (INV-7):检查接收中记录数.sql

    select      msi.segment1           物料编码,       msi.description          物料描述,      sum(rs.quantity)  ...

  8. javascript第十五课:DOM

    dom就是文档,就是整个网页的简称,dom里面的标签就是对象 使用javascript进行DHMTL网页开发(Dynamic Html 动态网页) dom就是把html页面模拟成一个对象,顶级对象wi ...

  9. K-近邻算法python实现

    内容主要来源于机器学习实战这本书.加上自己的理解. 1.KNN算法的简单描写叙述 K近期邻(k-Nearest Neighbor.KNN)分类算法能够说是最简单的机器学习算法了. 它採用測量不同特征值 ...

  10. &lt;转&gt;凯文&#183;凯利斯坦福演讲-预言未来20年科技潮流

    Note:未来全部的生意都是关于数据的生意,近场通信.自组网介入网络.人工智能...,如今的IT科技界是否仅仅是冰山一角.斑斓舞台帷幕的一丝缝隙? 原文出处: 中欧管理工商学院   欢迎分享原创到伯乐 ...