题意:给定 n, t, c 和 n 个数,问你在这 n 个数中有多少连续的 c 个数,并且这个 c 个数不大于 t。

析:很简单么,是滑动窗口,从第一个开始遍历,如果找到 c 个数,那么让区间前端点加1,如果找不到,那么就区间前端等于后区间+1.

代码如下:

 #include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 2e5 + 15;
const int INF = 0x3f3f3f3f;
int a[maxn]; int main(){
int n, t, c;
while(cin >> n >> t >> c){
for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
int s = 0, e = 0;
int cnt = 0;
int ans = 0;
while(e < n){
while(a[e] <= t && cnt < c && e < n) ++cnt, ++e; if(cnt == c){
--cnt;
++ans;
}
else{
++e;
cnt = 0;
}
}
cout << ans << endl;
}
return 0;
}

CodeForces 427B Prison Transfer (滑动窗口)的更多相关文章

  1. codeforces B. Prison Transfer

    题意:输入n,t,c,再输入n个数,然后问有多少个连续区间内的最大值小于等于t; #include <cstdio> #include <cstring> #include & ...

  2. CodeForces 701C They Are Everywhere (滑动窗口)

    题目链接:http://codeforces.com/problemset/problem/701/C 题意:找到字符串中能包含所有元素的最短字符串长度. 利用“滑动窗口”解题 解题思路: 1. 遍历 ...

  3. Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq

    B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...

  4. CodeForces 279B Books (滑动窗口)

    题意:给定n本书的阅读时间,然后你从第 i 本开始阅读,问你最多能看多少本书在给定时间内. 析:就是一个滑动窗口的水题. 代码如下: #pragma comment(linker, "/ST ...

  5. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  6. [CF580B]Kefa and Company(滑动窗口)

    题目链接:http://codeforces.com/problemset/problem/580/B 某人有n个朋友,这n个朋友有钱数m和关系s两个属性.问如何选择朋友,使得这些朋友之间s最大差距小 ...

  7. [LeetCode] Sliding Window Maximum 滑动窗口最大值

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...

  8. TCP/IP 协议中的滑动窗口

    一个例子明白发送缓冲区.接受缓冲区.滑动窗口协议之间的关系. 在上面的几篇文章中简单介绍了上述几个概念在TCP网络编程中的关系,也对应了几个基本socket系统调用的几个行为,这里再列举一个例子,由于 ...

  9. Storm Windowing storm滑动窗口简介

    Storm Windowing 简介 Storm可同时处理窗口内的所有tuple.窗口可以从时间或数量上来划分,由如下两个因素决定: 窗口的长度,可以是时间间隔或Tuple数量: 滑动间隔(slidi ...

随机推荐

  1. Java GC日志查看

    Java GC类型 Java中的GC有哪几种类型? 参数 描述 UseSerialGC 虚拟机运行在Client模式的默认值,打开此开关参数后, 使用Serial+Serial Old收集器组合进行垃 ...

  2. Easyui combotree 获取自定义ID属性方法

    1.设置属性 <input id="cc" class="easyui-combotree" data-options="url:'tree_d ...

  3. 5月9日上课笔记-网页定位、网页动画【HTML5】

    一.网页定位 position: static (默认值) relative 相对定位(相对原来的位置) right left botton top absolute 绝对定位 fixed: 固定定位 ...

  4. C++ 11 自旋锁

    // Spin lock implementation. // BasicLockable. // Async-signal safe. // unlock() "synchronizes ...

  5. Nginx加状态监控

    安装Nginx时加上        –with-http_stub_status_module 在nginx.conf server location /nginx_status { stub_sta ...

  6. python 之 itertools模块

    官方:https://yiyibooks.cn/xx/python_352/library/itertools.html 参考: https://blog.csdn.net/neweastsun/ar ...

  7. canvas绘制矩形

    canvas绘制矩形 方法 fillRect(x, y, width, height) 画一个实心的矩形 clearRect(x, y, width, height) 清除一块儿矩形区域 stroke ...

  8. EMQ、Websocket、MQTT

    mqtt.fx的安装和使用 https://blog.csdn.net/nicholaszao/article/details/79211965 EMO 使用说明 http://emqtt.com/d ...

  9. 1.docker学习之简介

    什么是Docker Docker是一个开源的应用容器引擎.通俗来说:所谓开源,就是指Docker是开放源代码的,比如用户可以免费使用该源代码, 并在该源代码的基础上自由修改或传播.所谓引擎,指的是程序 ...

  10. pipenv 简要指南

    pipenv 简要指南 pipenv是requests作者的一个项目, 整合了virtualenv, pip, pipfile, 用于更方便地为项目建立虚拟环境并管理虚拟环境中的第三方模块. 安装 直 ...