2014 Super Training #8 B Consecutive Blocks --排序+贪心
当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了。
解法不想写了,可见: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 --排序+贪心的更多相关文章
- 2014 Super Training #6 H Edward's Cola Plan --排序+二分
原题: ZOJ 3676 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3676 题意:给每个朋友一瓶可乐,可乐有普通和高 ...
- 2014 Super Training #1 F Passage 概率DP
原题: HDU 3366 http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排 ...
- 2014 Super Training #8 A Gears --并查集
题意: 有N个齿轮,三种操作1.操作L x y:把齿轮x,y链接,若x,y已经属于某个齿轮组中,则这两组也会合并.2.操作Q x y:询问x,y旋转方向是否相同(等价于齿轮x,y的相对距离的奇偶性). ...
- 2014 Super Training #9 E Destroy --树的直径+树形DP
原题: ZOJ 3684 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3684 题意: 给你一棵树,树的根是树的中心(到其 ...
- 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个 ...
- 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂
原题:ZOJ 3774 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...
- 2014 Super Training #7 C Diablo III --背包问题(DP)
原题: ZOJ 3769 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 一个带有一些限制的背包问题. 假设在没有限 ...
- 2014 Super Training #7 E Calculate the Function --矩阵+线段树
原题:ZOJ 3772 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3772 这题算是长见识了,还从没坐过矩阵+线段树的题 ...
- 2014 Super Training #7 B Continuous Login --二分
原题:ZOJ 3768 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3768 一个结论:一个正整数总能用不超过三个前n项相 ...
随机推荐
- Ahjesus Nodejs01 环境搭建及运行
访问http://nodejs.org/,根据系统选择下载文件,我用的win7 64 安装一路下一步直到完成 运行cmd输入node -v查看是否安装成功 成功会显示版本号 到此环境搭建完毕 ==== ...
- 类库LinqToExcel的介绍
LinqToExcel是一个.net framework平台下开源项目,它主要实现了LINQ的语法查询Excel电子表格.类型之前的LINQToXXX如果你是LINQ语法糖爱好者那最适 ...
- oschina github使用指南
我的github仓库开通,https://git.oschina.net/zhjh256. 1.打开https://git.oschina.net/signup,没有账号的话,则新创建账号. 2.从h ...
- mvc与三层结构终极区别
http://blog.csdn.net/csh624366188/article/details/7183872 http://www.cnblogs.com/zhhh/archive/2011/0 ...
- [WP8] ListBox的Item宽度自动填满
[WP8] ListBox的Item宽度自动填满 范例下载 范例程序代码:点此下载 问题情景 开发WP8应用程序的时候,常常会需要使用ListBox作为容器来呈现各种数据集合.但是在ListBox呈现 ...
- js判断客户端平台
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 浅析对象访问属性的"."和"[]"方法区别
在JavaScript中通常使用”."运算符来存取对象的属性的值.或者使用[]作为一个关联数组来存取对象的属性.但是这两种方式有什么区别了? 例如,读取object中的property属性值 ...
- 多线程基础 (八)NSOperation相关
额外的参考学习可以学习:http://www.cnblogs.com/YouXianMing/p/3707403.html 1.NSOperation简介 NSOperation的作用 配合使用N ...
- IOS的UI基础02
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- IOS开发之功能模块--自定义UITabBarViewController的备用代码
前言:因为常用,所以我就备份到这里,然后如果需要修改,可以根据需求进行相关的更改. @implementation YMTabBarController - (void)viewDidLoad { [ ...