当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了。

解法不想写了,可见:http://blog.csdn.net/u013368721/article/details/28071241

其实就是滑动窗口的思想。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define N 100007
#define M 33 struct node
{
int col,ind;
}p[N]; int cmp(node ka,node kb)
{
if(ka.col == kb.col)
return ka.ind < kb.ind;
return ka.col < kb.col;
} int main()
{
int i,j,now,cnt,L;
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=;i<=n;i++)
{
scanf("%d",&p[i].col);
p[i].ind = i;
}
sort(p+,p+n+,cmp);
L = ;
now = m;
cnt = ;
int maxi = ;
for(i=;i<=n;i++)
{
if(p[i].col == p[i-].col)
{
now -= (p[i].ind-p[i-].ind-);
cnt++;
while(now < ) //滑动
{
now += p[L+].ind-p[L].ind-;
cnt--;
L++;
}
maxi = max(maxi,cnt);
}
else
{
maxi = max(cnt,maxi);
now = m;
L = i;
cnt = ;
}
}
maxi = max(maxi,cnt);
printf("%d\n",maxi);
}
return ;
}

2014 Super Training #8 B Consecutive Blocks --排序+贪心的更多相关文章

  1. 2014 Super Training #6 H Edward's Cola Plan --排序+二分

    原题: ZOJ 3676  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3676 题意:给每个朋友一瓶可乐,可乐有普通和高 ...

  2. 2014 Super Training #1 F Passage 概率DP

    原题: HDU 3366   http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排 ...

  3. 2014 Super Training #8 A Gears --并查集

    题意: 有N个齿轮,三种操作1.操作L x y:把齿轮x,y链接,若x,y已经属于某个齿轮组中,则这两组也会合并.2.操作Q x y:询问x,y旋转方向是否相同(等价于齿轮x,y的相对距离的奇偶性). ...

  4. 2014 Super Training #9 E Destroy --树的直径+树形DP

    原题: ZOJ 3684 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3684 题意: 给你一棵树,树的根是树的中心(到其 ...

  5. 2014 Super Training #9 C E - Cup 2 --记忆化搜索

    原题:ZOJ 3681 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3681 题意:给一个m,n,m表示m个人,可以把m个 ...

  6. 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂

    原题:ZOJ 3774  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...

  7. 2014 Super Training #7 C Diablo III --背包问题(DP)

    原题: ZOJ 3769 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 一个带有一些限制的背包问题. 假设在没有限 ...

  8. 2014 Super Training #7 E Calculate the Function --矩阵+线段树

    原题:ZOJ 3772 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3772 这题算是长见识了,还从没坐过矩阵+线段树的题 ...

  9. 2014 Super Training #7 B Continuous Login --二分

    原题:ZOJ 3768 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3768 一个结论:一个正整数总能用不超过三个前n项相 ...

随机推荐

  1. Represent code in math equations

    Introduce The article shows a way to use math equations to represent code's logical. Key ideas logic ...

  2. 基于进程的Quartz.NET管理系统QuartzService(一)

    需求 在处理定时任务大家可能都用过Quartz.NET,但在生产环境中大家肯定也遇到过如下的问题: 发布的时候需要停掉所有的Job,再整个一起打包发布 没有管理界面(其实在github也有几个这方面的 ...

  3. LinQ实战学习笔记(四) LINQ to Object, 常用查询操作符

    这一篇介绍了下面的内容: 查询object数组 查询强类型数组 查询泛型字典 查询字符串 SelectMany 索引 Distinct操作符 排序 嵌套查询 分组 组连接 内连接 左外连接 交叉连接 ...

  4. RadioButton 自定义控件

    在res/drawable新建radiobutton.xml(本案例为video——evaluate.xml)如下 <?xml version="1.0" encoding= ...

  5. ADO.NET 完整的修改和删除

    namespace 完整修改{ class Program { static void Main(string[] args) { bool has = false; Console.Write(&q ...

  6. [js开源组件开发]js手机联动选择日期 开源git

    js手机联动选择日期 这里在前面的<js手机联动选择地区>的基础上,改造数据源之后形成的一个日期的选择器,当然你可以使用之前的PC上模式的<日期控件>,它同时也支持手机端,ht ...

  7. JavaScript焦点轮播图

    在慕课学习了JavaScript焦点轮播图特效,在此做一个整理. 首先是html结构,我用的是本地同文件夹下的三张图片,多出来的第一张(pic3副本)和最后一张图片(pic1副本)是为了实现无缝切换效 ...

  8. 实验12:Problem I: 成绩排序

    Home Web Board ProblemSet Standing Status Statistics   Problem I: 成绩排序 Problem I: 成绩排序 Time Limit: 1 ...

  9. SQL Server 分组 去除从复列

    下面先来看看例子: table表 字段1 字段2 id        name 1           a 2           b 3           c 4           c 5    ...

  10. SharePoint 2010 ——自定义上传页面与多文件上传解决方案

    最近项目遇到一个很麻烦的问题,原以为很容易解决,结果搞了那么久,先开个头,再慢慢写 SharePoint 2010 ——自定义上传页面与多文件上传解决方案 1.创建Sharepoint空白项目,创建应 ...