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

解法不想写了,可见: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. ahjesus sql2005+游标示例

    DECLARE @TypeId INT, @Price1 FLOAT, @Original FLOAT DECLARE my_cursor CURSOR SCROLL FOR SELECT TypeI ...

  2. ABAP:区别CALL SCREEN/SET SCREEN/LEAVE TO SCREEN

    1,CALL SCREEN XXXX将在Screen调用栈(CALL STACK)上面添加一层调用(进栈),调用XXXX的PBO和PAI,如果XXXX的Next Screen不为0,那么将继续其Nex ...

  3. .NET破解之轻量万能自定义信息管理系统

    一般敢说万能的莫非真有两把刷子.今天来破解试试,看效果好用不. 下载:http://down.chinaz.com/soft/36780.htm 补丁: http://www.t00y.com/fil ...

  4. Interoperability between Java and SharePoint 2013 on Premises

    http://ctp-ms.blogspot.com/2012/12/interoperability-between-java-and.html   Introduction One of the ...

  5. Force.com微信开发系列(二)用户消息处理

    Force.com是国际知名的云平台公司,成功配置好Force.com作为微信公开号的服务端后,接下来需要的任务是处理用户发送的消息.当普通微信用户向公众账号发消息时,微信服务器将POST消息的XML ...

  6. 2015年第8本(英文第7本):the city of ember 微光城市

    书名:the City of Ember(中文名:微光城市) 作者:Jeanne DuPrau 单词数:6.2万 不重复单词数:未知 首万词不重复单词数:未知 蓝思值:未知 阅读时间:2015年4月2 ...

  7. 我的GTD中收集的书单

    在几年的GTD过程中,收集了一些想读的书目,没有系统地整理,每当读完一本之后,就翻翻书单,寻找下一本感兴趣的书,书是不可能读完的,只能找有兴趣的.符合自己目标方向的.有些书记录了豆瓣上的评分,虽然不是 ...

  8. Ubuntu 14.04下安装JDK8

    本文地址:http://www.cnblogs.com/archimedes/p/ubuntu-jdk8.html,转载请注明源地址. 欢迎关注我的个人博客:www.wuyudong.com, 更多云 ...

  9. iOS设计模式之单例模式

    单例模式 基础理解 所有类都有构造方法,不编码则系统默认生成空的构造方法,若有显示定义的构造方法,默认的构造方法就会失效. 单例模式(Singleton):保证一个类仅有一个实例,并提供一个访问它的全 ...

  10. IOS Quartz2D简介

    Quartz2D 简介( 后续会有相关应用) 第一部分 绘制直线 代码示例: - (void)drawRect:(CGRect)rect{ //获取图形上下文 CGContextRef cxConte ...