priority_queue 优先队列 hdu裸题。

优先队列:可以当做一个堆用,对进入此结构的类型,可以找队首的元素。

开库:#include<queue>

定义: priority_queue<type> Q;

type:int类型  priority<int> Q; 默认Q.top为队列中最大的;

当我们要在队列中放入其他类型时,我们要用struct 在其中定义 operator < ;

结构如下:

定义 <int> Q.top() 为最小;

struct Point

{

  int i;

  bool operator < (const Point &A) const{

    return A.i<i;

  }

}

priority_queue<Point>Q;

查找队首:Q.top();

检查队列是否为空:Q.empty();

弹出队首:Q.pop();

队列清空:while(!Q.empty())  Q.pop();

时间: 2024-10-11 17:53:16

priority_queue 优先队列 hdu裸题。的相关文章

HDU 4893 线段树裸题

Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2512    Accepted Submission(s): 751 Problem Description Recently, Doge got a funny birthday present from his new friend, Pro

HDU 1102 最小生成树裸题,kruskal,prim

1.HDU  1102  Constructing Roads    最小生成树 2.总结: 题意:修路,裸题 (1)kruskal //kruskal #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b using na

HDU 4027 Can you answer these queries? 线段树裸题

题意: 给定2个操作 0.把区间的每个数sqrt 2.求和 因为每个数的sqrt次数很少,所以直接更新到底,用个标记表示是否更新完全(即区间内的数字只有0,1就不用再更新了) #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #incl

HDU 4280 Island Transport 网络流裸题

非递归版好像被卡掉了,其他2个板子都能过. #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<vector> using namespace std; #define ll int const int MAXN = 100100;//点数的最大值 const int MAXM = 400010;//边数的最大值 const in

HDU 2602 Bone Collector(01背包裸题)

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 60469    Accepted Submission(s): 25209 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bo

HDU 3376 &amp;&amp; 2686 方格取数 最大和 费用流裸题

题意: 1.一个人从[1,1] ->[n,n] ->[1,1] 2.只能走最短路 3.走过的点不能再走 问最大和. 对每个点拆点限流为1即可满足3. 费用流流量为2满足1 最大费用流,先给图取负,结果再取负,满足2 #include <stdio.h> #include <string.h> #include <iostream> #include <math.h> #include <queue> #include <set&

HDU 1162 Eddy&#39;s picture (prime算法_裸题)

Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result i

hdu1159 poj1458 LCS裸题

HDU 1159 题意:找LCS 思路:裸题 n*m的写法,我的写法好像比较奇怪...用一个ci保存s2第i位可以做为s1的公共子序列的最大值,s1的每一位遍历s2,遍历的时候记录前面出现过的ci的最大值,ci一定是一个连序的上升序列,我的好像不是正经的LCS的算法,改天还是要学习一个的 AC代码: #include "iostream" #include "string.h" #include "stack" #include "qu

HDOJ-1232 畅通工程【并查集裸题】

题目传送门 : http://acm.hdu.edu.cn/showproblem.php?pid=1232 并查集的裸题 AC code: #include <iostream> #define MAXN 1050 using namespace std; int pre[MAXN]; int Find(int pos) { int r = pos; while (r != pre[r]) r = pre[r]; int i = pos; while (i != r) { int t = p