
并查集
嘴角上扬*
渴求力量的家伙毫无疑问地都在追求着战斗!-更木剑八
展开
-
Acwing 145.超市(贪心+并查集)(优先队列+贪心)
解题思路 首先按照所能够获得的利润大小,对商品进行排序,然后分别从到期的那一天向前推,保证卖出的时间近量晚,每当找到还没有卖商品的那一天,就将其卖掉,令日期减1,代表当天已经卖出去了,日期需要向前推。 代码 #include<iostream> #include<algorithm> using namespace std; const int N =10010; struct node{ int x, y;//代表利润和保质期 }g[N]; int fa[N],d原创 2022-03-26 15:59:19 · 243 阅读 · 0 评论 -
Acwing 237. 程序自动分析(并查集+离散化)
思路 并查集的模板+离散化处理 代码 #include<iostream> #include<algorithm> #include<cstdio> using namespace std; typedef pair<int, int> PII; const int N =100010; int fa[N << 1],da[N << 1];//存放 x y 两个数据 所以要两倍 int x[N], y[N], op[N];//x原创 2022-03-26 11:50:12 · 419 阅读 · 0 评论