摘要:
P1937 [USACO10MAR] Barn Allocation G 所用算法:线段树:区间加法修改+求区间最小值 核心思路:贪心算法,优先满足右端点靠前的区间,每遍历一个区间我们就区间减1,每次检察是否有最小值=0的出现就不能再减了,这样就可以贪心的求出最多的区间数。 include<bits 阅读全文
摘要:
#include<bits/stdc++.h> using namespace std; const int N=1e4+10; int n,p,k,m; int T; int a[N]; int main() { cin>>T; while(T--) { cin>>n>>k>>p>>m; for( 阅读全文
摘要:
https://www.luogu.com.cn/problem/P2168#ide #include<cstdio> #include<cstring> #include<queue> #include<algorithm> #define ll long long using namespace 阅读全文
摘要:
我们用并查集求最大值,然后看有多少个没有闭环的并查集(有邻居数<=2的就是未闭环),设未闭环的总共有num个。若num>0,那么答案就是cnt-num+1个。注意每一次要状态恢复 #include<bits/stdc++.h> using namespace std; const int N=2e5 阅读全文
摘要:
这道题教会了我并查集是可以动态删改的,关键在于判断其是否是连通分量的代表 #include<bits/stdc++.h> using namespace std; typedef long long LL; LL t,n,m1,m2,ans,a[500005],b[500005],fag[50000 阅读全文