Codeforces Round #244 (Div. 2)B. Prison Transfer(想法题)

传送门

Description

The prison of your city has n prisoners. As the prison can‘t accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.

For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.

Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,

  • The chosen c prisoners has to form a contiguous segment of prisoners.
  • Any of the chosen prisoner‘s crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn‘t want to take the risk of his running away during the transfer.

Find the number of ways you can choose the c prisoners.

Input

The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner‘s crime. The value of crime severities will be non-negative and will not exceed 109.

Output

Print a single integer — the number of ways you can choose the c prisoners.

Sample Input

4 3 32 3 1 1

1 1 12
11 4 22 2 0 7 3 2 2 4 9 1 4

Sample Output

2

0

6

思路

题解:

试了一发暴力,果断超时,后来想了下,我们只需要记录下超过t的数,然后根据相邻两次超过t的数的位置求得此段不超过t的最长区间,看看是否符合题意,然后就可以计算出有多少种方法了。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int a[maxn], pos[maxn] = {0};

int main()
{
    int n, t, c, p = 1, res = 0;
    scanf("%d%d%d", &n, &t, &c);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] > t)   pos[p++] = i;
    }
    pos[p++] = n + 1;
    if (pos[1] == 0)	res += 1 + (n - c);
    else
    {
        for (int i = 1; i < p; i++)
        {
            int len = pos[i] - pos[i - 1] - 1;
            if (len >= c)
            {
                res += 1 + (len - c);
            }
        }
    }
    printf("%d\n", res);
    return 0;
}

  

时间: 2024-08-26 17:01:48

Codeforces Round #244 (Div. 2)B. Prison Transfer(想法题)的相关文章

Codeforces Round #244 (Div. 2) B. Prison Transfer

题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin >> n >> t >> c; int a,cnt = 0, res =0;; for(int i = 0 ; i < n ; ++ i) { cin >> a; if(a > t ){ if(cnt > c-1) res+=cnt-c+1;

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

B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/427/B Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c

Codeforces Round #345 (Div. 2)C. Watchmen(想法题)

传送门 Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan,

Codeforces Round #244 (Div. 2)

A. Police Recruits B. Prison Transfer A,B两个是水题. C. Checkposts DFS找出所有的环就行了. 每次搜索一个结点u时,给u加一个递增标号low[u],同时记录搜索u及u的子结点过程中遇到的最小标号minc,也就是当搜索u的子结点v时,minc = min(minc, low[v]).搜索完成后,如果minc < low[u],说明搜索u的子结点时又回到了u的父结点,也就是说u在一个环中,然后求出这个环的最小费用及取到最小费用的结点数. D.

Codeforces Round #244 (Div. 2)——Match &amp; Catch

题目链接 题意:给两个长度分别为n和m的序列,现在有两种操作:1.分别选择两个序列的一个非空前缀,切两个前缀的最后一位相同,删除之,得到1分(只累计),消耗e:2.直接删除两个序列,消耗值定于两个序列之前删除的元素个数之和,并且使得得到的分有效(之前没有有效分) 分析: 首先,问题其实就是转化成,进行若干次操作1,然后进行操作2 还要找到一个判别标准,来评判较优的状态(贪心) 每次的消耗值比较大,其实可以计算出最大的删除次数,这个值不是很大 状态表示: 简单的,一个状态可以表示为串A的位置.串B

Codeforces Round #244 (Div. 2)——Checkposts

题目链接 题意: 给定n个点,每个点有一个权值的有向图.现在需要选定一些点,使得这些点权值和最小,且满足:如果i能到达j且j能到达i,那么i.j可以只选一个 分析: 强联通模板题 //使用时只更新G完成构图 //scc_cnt从1开始计数 //pre[]表示点在DFS树中的先序时间戳 //lowlink[]表示当前点和后代能追溯到的最早祖先的pre值 //sccno[]表示点所在的双连通分量编号 //vector<int> G保存每个点相邻的下一个点序号 //stack<Edge>

Codeforces Round #244 (Div. 2) A. Police Recruits

题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> n; int a,recruit = 0, crimes = 0;; for(int i = 0 ; i < n; ++ i){ cin >> a; if(a > 0) recruit+=a; else recruit?recruit-- : crimes++; } cout<&

Codeforces Round #244 (Div. 2)D (后缀自动机)

Codeforces Round #244 (Div. 2)D (后缀自动机) (标号为0的节点一定是null节点,无论如何都不能拿来用,切记切记,以后不能再错了) 这题用后缀自动机的话,对后缀自动机的很多性质有足够深刻的理解.没想过后缀数组怎么做,因为不高兴敲.... 题意:给出两个长度均不超过5000的字符串s1,s2,求这两个串中,都只出现一次的最短公共子串. 解题思路:求的是公共子串,然后对出现的次数又有限制,第一想法就是后缀自动机啊,后缀自动机处理子串出现次数再合适不过了.做法是这样的

Codeforces Round #244 (Div. 2)D (后缀自己主动机)

Codeforces Round #244 (Div. 2)D (后缀自己主动机) (标号为0的节点一定是null节点,不管怎样都不能拿来用,切记切记,以后不能再错了) 这题用后缀自己主动机的话,对后缀自己主动机的非常多性质有足够深刻的理解. 没想过后缀数组怎么做.由于不高兴敲... . 题意:给出两个长度均不超过5000的字符串s1,s2,求这两个串中,都仅仅出现一次的最短公共子串. 解题思路:求的是公共子串,然后对出现的次数又有限制,第一想法就是后缀自己主动机啊,后缀自己主动机处理子串出现次