跳过正文
  1. Posts/

poj 3481 double queues

·1 分钟

http://acm.hdu.edu.cn/showproblem.php?pid=1908

看到有两个优先级,然后题目中又有queue。。。就想到了优先队列。。。

但是优先队列的cmp函数没搞懂,因为比较的是结构体,好像要重载< 什么的。

然而并不会。

其实用map就可以做。。。

map在插入的时候可以自动按关键字排序,简直好评如潮!

 1
 2
 3    /* ***********************************************
 4    Author :111qqz
 5    Created Time :2016年02月19日 星期五 15时44分06秒
 6    File Name :3481.cpp
 7    ************************************************ */
 8
 9    #include <algorithm>
10    #include <cstdio>
11    #include <iostream>
12    #include <cstring>
13    #include <string>
14    #include <cmath>
15    #include <map>
16    #include <stack>
17    #include <queue>
18
19    using namespace std;
20    typedef long long LL;
21    const int inf = 8E8;
22
23
24
25    int cmd;
26    map<int,int>a;
27    int p,k;
28
29    int main()
30    {
31
32        while (scanf("%d",&cmd)!=EOF&&cmd)
33        {
34           if (cmd==1)
35           {
36               scanf("%d %d",&k,&p);
37               a[p]=k;
38           }
39           if (cmd==2)
40           {
41               if (a.empty())
42               {
43                   cout<<"0"<<endl;
44               }
45               else
46               {
47                   cout<<a.rbegin()->second<<endl;
48                   a.erase(a.find(a.rbegin()->first));
49               }
50           }
51           if ( cmd==3 )
52           {
53               if (a.empty())
54               {
55                   cout<<"0"<<endl;
56               }
57               else
58               {
59                   cout<<a.begin()->second<<endl;
60                   a.erase(a.begin());
61               }
62           }
63        }
64
65    	return 0;
66    }

相关文章

poj 1833 排列

·1 分钟
http://poj.org/problem?id=1833 还是next_permutation. 这次是Int类型的 需要注意的是next_permutation是先判断时候有后继,返回一个bool值,如果为true,就转化到后继。

poj 1256 Anagram

·1 分钟
http://poj.org/problem?id=1256 题意是说求出一个字符串的全排列,按字典序 需要注意的是字典序和传统意义上的字典序不同

codeforces 548B Mike and Fun

·1 分钟
http://codeforces.com/problemset/problem/548/B 比赛的时候不懂为什么就没做出来…. 其实很容易想到一个o(q*(n+m))的做法… 就是每次更新,要同时更新当前更新行的最大连续和….O(m)可以完成…然后在O(n)扫一遍,找到所有行中的最大值。 然后需要注意的是,在第一次更改之前就要把每个行的最大值处理出来l.. 然后cf机器真是够快,O(nmq)的1.2S过。。。。

poj 2492 A Bug's Life (并查集)

·1 分钟
http://poj.org/problem?id=2492 Hint Huge input,scanf is recommended. 也是带种类的冰茶几。 由于只分了两类…我们还是可以按照上道题的做法。。