CodeForces 427B Prison Transfer

题意:给定 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;
}
时间: 2024-11-08 10:55:33

CodeForces 427B Prison Transfer的相关文章

codeforces B. Prison Transfer

题意:输入n,t,c,再输入n个数,然后问有多少个连续区间内的最大值小于等于t; 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 200100 5 using namespace std; 6 7 int t,n,c; 8 int a[maxn]; 9 int sum[maxn]; 10 11 int main() 12 { 13 scanf("%d%

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 #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 - 427B (模拟题)

Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status 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 t

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

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.

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理

A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/A Description An old watchmaker has n stopped nano alarm-clocks numbered with integers from 1 to n. Nano alarm-clocks count time in hours, and

codeforces Gym 100187J J. Deck Shuffling dfs

J. Deck Shuffling Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/J Description The world famous scientist Innokentiy continues his innovative experiments with decks of cards. Now he has a deck of n cards and k s