优先队列

CF854C Planning优先队列|set

拥有回忆 提交于 2019-11-26 20:50:00
C. Planning Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i -th of them is planned to depart at the i -th minute of the day. Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created. All n scheduled flights must now depart at different minutes between ( k  + 1)-th and ( k  + 

优先队列重载

北城以北 提交于 2019-11-26 19:28:00
优先队列重载有三种写法: 第一种: struct node { int val, deep; friend bool operator < (node a, node b) { if(a.val == b.val) { return a.deep > b.deep; } return a.val > b.val; } }; 其中,当满足下列自己填写的条件时,队列就会按照从小到大来排序。 第二种: struct node { int val, deep; bool operator < (const node &a) const { if(val == a.val) { return deep > a.deep; } return val > a.val; } }; 第三种: struct node { int val, deep; }; bool operator < (const node &a, const node &b) { if(a.val == b.val) { return a.deep > b.deep; } return a.val > b.val; } 上面两种都是放结构体里面,第三种时放结构体外面。 来源: https://www.cnblogs.com/buhuiflydepig/p/11330996.html

ZOJ 1649 - Rescue BFS/优先队列

≯℡__Kan透↙ 提交于 2019-11-26 17:40:51
在HDOJ上提交通过以后,再在zoj上提交,结果得到了无数个WA,后来发现有一种情况我并没有考虑到 有几个关键的地方需要注意: 1. Angel的朋友不只有一个,可能有多个 2. guard的存在可能会破坏广度优先树 解决办法: BFS的做法:必须要保存guard与可行点‘.’的插入同步,因为guard的costTime不同,应该先不改变其坐标,costTime增加一以后,设为已被访问,‘x’变为‘.’或者‘#’,重新入队,此时,guard已被插入到队列的尾部,这样一来,guard与‘.’就可以同步了 View Code 1 #include <math.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include < string .h> 5 #include <memory.h> 6 7 char maze[ 210 ][ 210 ]; 8 int vis[ 210 ][ 210 ]; 9 int dx[] = {- 1 , 1 , 0 , 0 }; 10 int dy[] = { 0 , 0 , - 1 , 1 }; 11 int nNum, mNum, i, j, sx, sy; 12 13 struct Node 14 { 15 int x; 16 int y; 17 int step; 18 }; 19 20 int

[优先队列][贪心]JZOJ 6274 梦境

随声附和 提交于 2019-11-26 15:44:31
Description Input Output Sample Input 2 2 1 3 2 4 1 3 Sample Output 2 Data Constraint Hint 分析 把区间按照左端点排序,然后枚举转折点,把右端点最靠前的包含转折点的区间与其匹配一定最优(正确性难证) 最靠前可以用优先队列维护,时间复杂度nlogn #include <iostream> #include <cstdio> #include <algorithm> #include <queue> using namespace std; typedef long long ll; const int N=2e5+10;; int n,m; struct Intervals { ll l,r; friend bool operator < (Intervals a,Intervals b) { return a.r>b.r; } }a[N]; ll b[N],ans; bool vis[N]; priority_queue<Intervals> q; bool CMP(Intervals a,Intervals b) { return a.l<b.l; } int main() { freopen("dream.in","r",stdin); freopen("dream.out","w"