POJ 3481 Double Queue STLmap和set新学到的一点用法
2013-08-08
这个题应该是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新学到的一点用法的更多相关文章
- POJ 3481 Double Queue(Treap模板题)
Double Queue Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15786 Accepted: 6998 Des ...
- POJ 3481 Double Queue(STL)
题意 模拟银行的排队系统 有三种操作 1-加入优先级为p 编号为k的人到队列 2-服务当前优先级最大的 3-服务当前优先级最小的 0-退出系统 能够用stl中的map 由于map本身 ...
- POJ 3481 Double Queue(set实现)
Double Queue The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Buchares ...
- POJ 3481 Double Queue
平衡树.. 熟悉些fhq-Treap,为啥我在poj读入优化不能用啊 #include <iostream> #include <cstdio> #include <ct ...
- POJ 3481 Double Queue (treap模板)
Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest ...
- poj 3841 Double Queue (AVL树入门)
/****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...
- hdu 1908 Double Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...
- 【Map】Double Queue
Double Queue Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13258 Accepted: 5974 Des ...
- poj 2259 Team Queue
Team Queue Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2977 Accepted: 1092 Descri ...
随机推荐
- Python即时网络爬虫:API说明
API说明——下载gsExtractor内容提取器 1,接口名称 下载内容提取器 2,接口说明 如果您想编写一个网络爬虫程序,您会发现大部分时间耗费在调测网页内容提取规则上,不讲正则表达式的语法如何怪 ...
- FMDB将对象放进数据库[一]
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- Vue.js实现拼图游戏
Vue.js实现拼图游戏 之前写过一篇<基于Vue.js的表格分页组件>的文章,主要介绍了Vue组件的编写方法,有兴趣的可以访问这里进行阅读:http://www.cnblogs.com/ ...
- C# Chart 折线图 多条数据展示
private void btn_Click(object sender, EventArgs e) { DBHelper db = new DBHelper(); DataSet ds = db.G ...
- Oracle EBS-SQL (INV-8):检查物料入库明细信息.sql
select a.vendor_number 供应商编码 ,a.vendor_name 供应商名称 ,a.item_nu ...
- 做为一个Java程序员,你需要哪些傍身的技能?
最近总有些断断续续的思考,想想从我入行以来,我到底学会了什么,做成过什么,以后要做什么,如何提升自己······· 工作3年了,常听人说3年,5年,10年是程序员的坎,每过一个都会有新的想法,新的改变 ...
- Unix/Linux环境C编程入门教程(27) 内存那些事儿
calloc() free() getpagesize() malloc() mmap() munmap()函数介绍 calloc(配置内存空间) 相关函数 malloc,free,realloc,b ...
- C11 memory_order
概念: 摘录自:http://preshing.com/20120913/acquire-and-release-semantics/ Acquire semantics is a property ...
- flex-linkbutton
LinkButton 控件是没有边框的 Button 控件,当用户将鼠标移动到该控件位置时,其内容将加亮显示.这些特征通常借助包含在浏览器页面中的 HTML 链接进行展示.为使 LinkButton ...
- linux修改系统时间date命令加clock -w
http://m.jb51.net/LINUXjishu/117784.html 修改linux系统时间的方法(date命令) 11-18 23:22:27作者:脚本之家 命令格式为: date -s ...