最棒的网站建设,浙江省建设厅网站图审备案,网站建设实习周记,个人做网站报价正题
给出n个数#xff0c;删去k种数#xff0c;使一种数连续的最长。 解题思路
用hash表储存每种数在leftleft到ii这个区间内没种数的个数,然后如果这个区间内的种数超过k+1个那么就移动left role=presentationleftleft指针并没次从hash中弹出一个…正题
给出n个数删去k种数使一种数连续的最长。 解题思路
用hash表储存每种数在leftleftleft到iii这个区间内没种数的个数,然后如果这个区间内的种数超过k+1个那么就移动left" role="presentation">leftleftleft指针并没次从hash中弹出一个数知道满足条件最后统计一下答案就好了。 代码
#includecstdio
#includecstring
#includealgorithm
#define hashmath(x) x%p
using namespace std;
const int p600001;
int n,k,a[100001],hash[p],v[p],s,left,x,need,maxs;
int locate(int x)
{int whashmath(x),i0;while (hash[(wi)%p]!0hash[(wi)%p]!xip) i;return (wi)%p;
}
int main()
{scanf(%d%d,n,k);k;for (int i1;in;i)scanf(%d,a[i]);for (int i1;in;i){int wlocate(a[i]);if (!v[w]) x;//是一个新种v[w];hash[w]a[i];//正常操作while(xk){int wzlocate(a[left]);v[wz]--;if (!v[wz]){x--;//这种数已经没了hash[wz]0;} left;}maxsmax(maxs,v[w]);//统计答案}printf(%d,maxs);
}