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%d%d",&n,&t,&c);
14     memset(sum,0,sizeof(sum));
15     for(int i=1; i<=n; i++)
16     {
17         int x;
18         scanf("%d",&x);
19         if(x<=t)
20         {
21             a[i]=1;
22         }
23         sum[i]=sum[i-1]+a[i];
24     }
25     int ans=0;
26     for(int i=1; i+c-1<=n; i++)
27     {
28         if(sum[i+c-1]-sum[i-1]==c)
29         {
30             ans++;
31         }
32     }
33     printf("%d\n",ans);
34     return 0;
35 }

时间: 2024-11-14 03:29:54

codeforces B. Prison Transfer的相关文章

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 = 0x3f3f3f

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 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.

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

大神刷题表

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