hdu 1908 double queues

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

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

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

然而并不会。

其实用map就可以做。。。

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
const int inf = 8E8;

int cmd;
map<int,int>a;
int p,k;

int main()
{

    while (scanf("%d",&cmd)!=EOF&&cmd)
    {
       if (cmd==1)
       {
           scanf("%d %d",&k,&p);
           a[p]=k;
       }
       if (cmd==2)
       {
           if (a.empty())
           {
               cout<<"0"<<endl;
           }
           else
           {
               cout<<a.rbegin()->second<<endl;
               a.erase(a.find(a.rbegin()->first));
           }
       }
       if ( cmd==3 )
       {
           if (a.empty())
           {
               cout<<"0"<<endl;
           }
           else
           {
               cout<<a.begin()->second<<endl;
               a.erase(a.begin());
           }
       }
    }

    return 0;
}
时间: 2024-10-29 15:42:31

hdu 1908 double queues的相关文章

HDU 1908 Double Queue&lt;Set&gt;

Problem Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of th

hdu 1908 Double Queue

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using mod

POJ 3481 &amp; HDU 1908 Double Queue (map运用)

题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by

hdu 1908 Double Queue (map)

# include <stdio.h> # include <algorithm> # include <iostream> # include <string.h> # include <string> # include <map> using namespace std; int main() { map<int,int>q; map<int,int>::iterator p; int n,name,nu

HDU 1908 Double Queue(set)

Problem Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of th

HDU 4259 Double Dealing【简单群置换】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4259 题目大意:给出n张卡片以及k个人,现在对卡片进行分堆,然后分发(这样卡片改变了顺序),依次这样问多少次后卡片顺序回到原来一样. 比如给出的10,3. 第一次分堆是这样的 第一人:1,4,7,10 第二人:2,5,8 第三人:3,6,9 其顺序由1 2 3 4 5 6 7 8 9 10 变成了 10 7 4 1 8 5 2 9 6 3 即: 10 3 第一次 10 7 4 1 8 5 2 9 6

HDU 4259(Double Dealing-lcm(x1..xn)=lcm(x1,lcm(x2..xn))

Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1924    Accepted Submission(s): 679 Problem Description Take a deck of n unique cards. Deal the entire deck out to k players in

HDU 4259 Double Dealing(置换群啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4259 Problem Description Take a deck of n unique cards. Deal the entire deck out to k players in the usual way: the top card to player 1, the next to player 2, the kth to player k, the k+1st to player 1,

hdu 4529 Double Dealing (置换群)

# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; __int64 gcd(__int64 a,__int64 b) { if(b==0) return a; return gcd(b,a%b); } int main() { int n,k,i,j,vis[810],m,num[810],x; __int64 res,cot; while(~scanf(