思路 考虑比较朴素的解法,枚举每个长度为\(k+1\)的区间,然后统计区间中出现次数最多的颜色.这样的话复杂度为\(O(n*k)\)的,显然不行. 观察到统计每个区间中出现次数最多的颜色中,可以只用看每种颜色在区间中出现的最后一个位置,这样的话只需要我们开个桶统计一下数量就行. 所以就类似于尺取那样,维护颜色种类不超过\(k+1\)的区间,对于每次新加进来的值令其\(cnt++\),并且维护ans.当颜色种类超过\(k+1\)时,就减去区间前面的值,因为它们与后面的颜色不可能再连在一起了. 因为…
https://www.luogu.org/problem/show?pid=3029 题目描述 Farmer John has hired a professional photographer to take a picture of some of his cows. Since FJ's cows represent a variety of different breeds, he would like the photo to contain at least one cow fro…
题目描述 Farmer John has hired a professional photographer to take a picture of some of his cows. Since FJ's cows represent a variety of different breeds, he would like the photo to contain at least one cow from each distinct breed present in his herd. F…
题目传送门 思路这道题目可以通过尺取法来完成 (我才不管什么必须用队列)什么是尺取法呢?顾名思义,像尺子一样取一段,借用挑战书上面的话说,尺取法通常是对数组保存一对下标,即所选取的区间的左右端点,然后根据实际情况不断地推进区间左右端点以得出答案.之所以需要掌握这个技巧,是因为尺取法比直接暴力枚举区间效率高很多,尤其是数据量大的时候,所以尺取法是一种高效的枚举区间的方法,一般用于求取有一定限制的区间个数或最短的区间等等.当然任何技巧都存在其不足的地方,有些情况下尺取法不可行,无法得出正确答案!对于…
题目描述 Farmer John's N cows (1 <= N <= 100,000) are lined up in a row. Each cow is identified by an integer "breed ID" in the range 0...1,000,000,000; the breed ID of the ith cow in the lineup is B(i). Multiple cows can share the same breed…
题目链接 看了看其他大佬的文章,为什么要控制右端呢 其实就是一个很简单的模拟队列趴... 难点就在于根据题意我们可以分析得一段合法区间内,不同种类个数不能超过k+2 哦当然,由于种类数范围过大,要对种类进行离散化,可以使用STL的map 剩下的就是模拟了,详见代码: #include<bits/stdc++.h> using namespace std; map<int,int> f; int ty,tot,k,n,ans; ]; ]; int main(){ scanf(&quo…
P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N <= 1,000) have escaped and gone on a rampage! Each minute a cow is outside the fence, she causes one dollar worth of dam…
P2853 [USACO06DEC]牛的野餐Cow Picnic 题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way path…
P2853 [USACO06DEC]牛的野餐Cow Picnic 题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way path…
3048: [Usaco2013 Jan]Cow Lineup Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 225  Solved: 159[Submit][Status][Discuss] Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row. Each cow is identified by an integer "breed ID&…