题意:给你n个数,找出一个最大的区间,满足:不同的数值个数不超过k;

    //我开始又看错题了、 以为是找出一个最大区间,里面的数的最大值不超过k;

思路:利用一个窗口滑动,左端点表示当前位置,右端点表示目前这段数列符合要求, 每增加一个长度,判断是否合理,不然平移左端点。                         思路来自:http://blog.csdn.net/u011528035/article/details/50521870#;

 #include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const int qq=1e6;
int num[qq];
int dp[qq];
int l,r,k,n,ans,dif,p,q; //定义的全局变量自动初始化为0(包括数组).
int main()
{
cin >> n >> k;
l=r=;
for(int i=;i<=n;++i){
cin >> num[i];
if(!dp[num[i]]) ++dif;
dp[num[i]]++;
r=i;
if(dif>k){
for(int j=l;j<=r;++j){
dp[num[j]]--;
if(!dp[num[j]]){
dif--;l=j+;break;
}
}
}
if(r-l+>ans){
ans=r-l+;q=l;p=r;
}
}
cout << q << " " << p << endl;
}

codeforces 616D的更多相关文章

  1. 【CodeForces 616D】Longest k-Good Segment

    题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...

  2. CodeForces 616D Longest k-Good Segment

    用队列维护一下即可 #include<cstdio> #include<cstring> #include<queue> #include<algorithm ...

  3. Educational Codeforces Round 5

    616A - Comparing Two Long Integers    20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. 手把手教你如何玩转消息中间件(ActiveMQ) https://blog.csdn.net/cs_hnu_scw/article/details/81040834

    #情景引入小白:起床起床起床起床....快起床~我:怎么了又,大惊小怪,吓到我了.小白:我有事有事想找你,十万火急呢~~我:你能有什么事?反正我不信..那你说说看~~小白:就是我有两个小表弟,叫大白和 ...

  2. C++ 之手写strcpy

    char *strcpy(char* strDest, const char*strSrc){ assert(strDest != NULL&&strSrc != NULL); cha ...

  3. docker相关教程【转】

    https://www.w3cschool.cn/docker/docker-run-command.html 运行容器 https://www.runoob.com/docker/docker-im ...

  4. NOIP模拟 17.8.17

    NOIP模拟17.8.17 A 小 G 的字符串文件名 输入文件 输出文件 时间限制 空间限制str.pas/c/cpp str.in str.out 1s 128MB[题目描述]有一天,小 L 给小 ...

  5. 利用Eclipse进行远程Debug

    这项功能真的十分赞,当我不想写junit test,又想调试在实际环境中才能起作用的Java程序,远程debug真的是太好用了. 参数:java -jar -Xdebug -Xrunjdwp:tran ...

  6. HDU - 4788 Hard Disk Drive (成都邀请赛H 水题)

    HDU - 4788 Hard Disk Drive Time Limit:1000MS   Memory Limit:32768KB   64bit IO Format:%I64d & %I ...

  7. @codeforces - 1276F@ Asterisk Substrings

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个包含 n 个小写字母的字符串 s,用 s 生成 n 个串 ...

  8. python系列之(1)BeautifulSoup的用法

    好久没更新博客了.打算写一个python的爬虫系列及数据分析.falg也不能随便立,以免打脸. python爬取内容,是过程,分析数据是结果,最终得出结论才是目的.python爬虫爬取了内容,一般都是 ...

  9. linux驱动开发满三年,回首一下基本看不到其它选择

    刚刚搞完一个处理器BSP项目,准备搞下一个自研处理器.说不上来什么喜悦,仅仅有些许茫然.没有刚毕业时对这个行业的痴迷,慢慢认同这仅仅是个谋生工具的想法. 回忆当初编写第一个驱动,就像上了战场.被长官踢 ...

  10. HDU_2035:人见人爱A^B

    Problem Description 求A^B的最后三位数表示的整数. 说明:A^B的含义是“A的B次方”   Input 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1< ...