ZOJ 3790 Consecutive Blocks 模拟题
problemCode=3790">Consecutive Blocks
先离散一下,然后模拟,把一种颜色i所在的位置都放入G[i]中。然后枚举一下终点位置,滑动窗体使得起点和终点间花费不超过K,求中间过程的最大值就可以。
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- #define N 100005
- set<int>myset;
- map<int,int>mp;
- set<int>::iterator p;
- int n ,k;
- int a[N];
- vector<int>s[N];
- int go(int cur){
- int now = k;
- int ans = 1, l = 0, siz = s[cur].size();
- int len = 1;
- for(int i = 1; i < siz; i++){
- if(s[cur][i-1] == s[cur][i]-1)
- {
- len++;
- ans = max(ans, len);
- continue;
- }
- now -= s[cur][i]-s[cur][i-1]-1;
- if(now>=0)
- { len++; ans = max(ans, len);}
- else
- {
- while(now<0)
- {
- l++;
- now += s[cur][l]-s[cur][l-1]-1;
- len--;
- }
- len++;
- }
- }
- return ans;
- }
- int main()
- {
- int T ,m,u,v,w, i ,j;
- while(~scanf("%d %d",&n,&k)){
- myset.clear();
- mp.clear();
- for(i=1;i<=n;i++)scanf("%d",&a[i]),myset.insert(a[i]);
- for(p=myset.begin(), i = 1; p!=myset.end(); p++, i++)
- mp.insert(pair<int,int>(*p,i)),s[i].clear();
- int top = i;
- for(i=1;i<=n;i++)
- {
- a[i] = mp.find(a[i])->second;
- s[a[i]].push_back(i);
- }
- int ans = 0;
- for(i=1;i<top;i++)
- ans = max(ans, go(i));
- printf("%d\n",ans);
- }
- return 0;
- }
- /*
- 13 3
- 1000000000 2 2 1 1 2 2 5 6 8 2 2 2
- */
ZOJ 3790 Consecutive Blocks 模拟题的更多相关文章
- zoj 3790 Consecutive Blocks 离散化+二分
There are N (1 ≤ N ≤ 105) colored blocks (numbered 1 to N from left to right) which are lined up in ...
- ZOJ 3790 Consecutive Blocks
大致题意就是给你一个数列,让你最多移除K个数字,使得连续的相同数字的长度最大,并求出最大长度. 我们将此序列按颜色排序,颜色相同的话按位置排序,那么排完序之后颜色相同的blocks就在一起,只是他们的 ...
- ZOJ 3790 Consecutive Blocks (离散化 + 暴力)
题目链接 虽然是一道暴力的题目,但是思路不好想.刚开始还超时,剪枝了以后1200ms,不知道为什么还是这么慢. 题意:给你n个点,每个点有一种颜色ci,给你至多k次删除操作,每次删除一个点,问最多k次 ...
- ZOJ 3818 Pretty Poem 模拟题
这题在比赛的时候WA到写不出来,也有判断ABC子串不一样不过写的很差一直WA 在整理清思路后重写一遍3Y 解题思路如下: 第一种情况:ABABA. 先判断开头的A与结尾的A,得到A的长度, 接着判断A ...
- Capture the Flag ZOJ - 3879(模拟题)
In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are us ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- ZOJ1111:Poker Hands(模拟题)
A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...
- Codeforces Beta Round #7 B. Memory Manager 模拟题
B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
随机推荐
- jQuery Ajax异步处理Json数据详解
先我们来看一个官方的实例使用 AJAX 请求来获得 JSON 数据,并输出结果: $("button").click(function(){ $.getJSON("dem ...
- Maven Jrebel 多模块热部署方案
近期在构建maven多模块项目时,发现web module依赖的其它模块,每次都要clean install成一个jar包,然后运行web module才能加载. 本生jrebel是配置在了web m ...
- 在非MFC程序中使用调试宏 ASSERT(),VERIFY()和 TRACE()
游戏制作已经开始采用C++了,却鲜有人选择使用MFC.但笔者觉得的 ASSERT(),VERIFY()和 TRACE()这几个宏很好用.所以就想自己写一个版本来适应Windows平台下不同的工程类型. ...
- Uva 552 Prime Ring Problem(dfs)
题目链接:Uva 552 思路分析:时间限制为3s,数据较小,使用深度搜索查找所有的解. 代码如下: #include <iostream> #include <string.h&g ...
- Eddy's爱好(dfs+容斥)
Eddy's爱好 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- JS获取中文拼音首字母,并通过拼音首字母高速查找页面内的中文内容
实现效果: 图一: 图二: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGVzdGNzX2Ru/font/5a6L5L2T/fontsize/400/f ...
- HDoj-1527-取石子游戏
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- c++,类的组合
1. 在A类中以B类的对象作为成员变量,称为类的组合(composition). 可以先看看这篇文章理解组合的用处: C++中组合的使用 http://blog.csdn.net/jia_xiaoxi ...
- 《算法导论》读书笔记之图论算法—Dijkstra 算法求最短路径
自从打ACM以来也算是用Dijkstra算法来求最短路径了好久,现在就写一篇博客来介绍一下这个算法吧 :) Dijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的 ...
- 限制QLineEdit的数值输入范围(一共4种限制器:QDoubleValidator, QIntValidator, QRegExpValidator, 和QRegularExpressionValidator)
在使用QLineEdit输入数值时,经常遇到限制其范围的需要,比如角太阳高度角范围为[-90,90],经度值范围[-180,180],方位角范围[0,360].Qt提供了QIntValidator和Q ...