P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected \(N\) diamonds (\(N \leq 50,000\) of varying sizes, and she wants to arrange so…
P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected NN diamonds (N \leq 50,000N≤50,000) of varying sizes, and she wants to arrange…
    解法众多的一道毒瘤题? 题目描述 奶牛Bessie很喜欢闪亮亮的东西(Baling~Baling~),所以她喜欢在她的空余时间开采钻石!她现在已经收集了\(N\)颗不同大小的钻石,现在她想在谷仓的两个陈列架上摆放一些钻石. Bessie想让这些陈列架上的钻石保持相似的大小,所以她不会把两个大小相差\(K\)以上的钻石同时放在一个陈列架上(如果两颗钻石的大小差值为\(K\),那么它们可以同时放在一个陈列架上).现在给出\(K\),请你帮Bessie确定她最多一共可以放多少颗钻石在这两个陈列…
题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected NN diamonds (N \leq 50,000N≤50,000) of varying sizes, and she wants to arrange some of them in a pair of display cases in…
题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected  diamonds () of varying sizes, and she wants to arrange some of them in a pair of display cases in the barn. Since Bessie…
由于相差不超过k才可以放在一起,要判断不超过k这个条件,显然我们需要排序 首先我们需要一个f数组,f[i]意义看代码开头注释, 假设我们可以选择的某一个区间是a[l]~a[r](已排序且最优(最长的意思)),那么这个区间要符合这样一个性质: a[r]-a[l]<=k 移项一下, a[r]<=k+a[l](r要尽可能大) 而a[l]中的l我们是枚举得到的,因此我们只需要求出对应的r即可 我们观察移项后的式子可以发现,我们要求的r其实是数列中小于等于k+a[l]的最大值 那么这显然是符合可二分性的…
算是一道dp 首先,排序好每一个架子上都是一段区间,然后只需要统计每个点向左向右最长延伸的区间. 所以我们预处理出每个点以左.以右最大能延伸的长度(最多能选几个差值不超过k的) 然后枚举每个点作为断点,sum取max即可 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int n,k,a[N],sum_l[N],sum_r[N]; int read(){ ; ch…
题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to temporarily close down his farm to save money in the meantime. The farm consists of NN barns connected with MM bidirectional paths between some pairs of…
传送门 题目大意: n个谷仓 ,每次关闭一个谷仓,问剩下没被关闭的谷仓是 否联通. 题解:并查集+倒序处理 代码: #include<iostream> #include<cstdio> #include<cstring> #define N 3030 using namespace std; int n,m,sumedge,cnt; int head[N],fa[N],q[N],ans[N],exit[N]; struct Edge{ int x,y,nxt; Edg…
P3145 [USACO16OPEN]分割田地Splitting the Field 题目描述 Farmer John's NN cows (3 \leq N \leq 50,0003≤N≤50,000) are all located at distinct positions in his two-dimensional field. FJ wants to enclose all of the cows with a rectangular fence whose sides are pa…