Codeforces 279 B Books

题意:给出n本书,总的时间t,每本书的阅读时间a[i],必须按照顺序来阅读,问最多能够阅读多少本书

有点像紫书的第七章讲的那个滑动区间貌似 维护一个区间的消耗的时间小于等于t,然后维护一个区间的最大值

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include <cmath>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<algorithm>
11 using namespace std;
12
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=100005;
17 int a[maxn],pre[maxn];
18
19 int main(){
20     int n,t;
21     scanf("%d %d",&n,&t);
22     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
23
24     pre[0]=0;
25     for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
26
27
28     int l=0;
29     int r=1;
30     int sum=0,ans=-1;
31     while(r<=n){
32         if((pre[r]-pre[l])<=t){
33             ans=max(ans,r-l);
34             r++;
35         }
36         else l++;
37     }
38     printf("%d\n",ans);
39     return 0;
40 }

时间: 2024-08-05 16:22:41

Codeforces 279 B Books的相关文章

Codeforces Round #279 (Div. 2) b

/**  * @brief Codeforces Round #279 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/11/27 15:29  * @edited  2014/11/27 20:40  * @type   * @note  */ #include <cstdio> #include <stack> #include <cstring> #include <vector>

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #279 (Div. 2) a

/**  * @brief Codeforces Round #279 (Div. 2) a  * @file a.cpp  * @author 面码  * @created 2014/11/26 17:05  * @edited  2014/11/26 17:05  * @type   *  */ #include <cstdio> #include <stack> #include <cstring> using namespace std; #define max

数学 Codeforces Round #308 (Div. 2) B. Vanya and Books

题目传送门 1 /* 2 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <vector> 10 #include <string> 11 #inc

Codeforces Round #279 (Div. 2) d

/**  * @brief Codeforces Round #279 (Div. 2) d  * @file d.cpp  * @author 面码  * @created 2014/12/09 10:58  * @edited  2014/12/09 10:58  * @type math greedy  * @note 自己的AC不了,参考别人的,重点是2和3都是质数,所以可以使用贪心求解.  */ #include <fstream> #include <iostream>

CodeForces 279B Books (滑动窗口)

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

Codeforces Round #279 (Div. 2) F. Treeland Tour(lis+dfs)

题目链接: huangjing 题意:告诉一个无向无环图,然后求在联通的路上的lis. 思路:枚举起点求lis 复杂度是n^2logn,貌似这复杂度对时间有点玄,估计是数据有点弱... 首先枚举起点,然后求lis,主要是用dfs求的,要用到回溯的思想,我觉得是只要更新了,就要保存那个操作,然后一旦这一次的搜索完成,那么就要立即回复g数组的值,因为有很多不同的路线,所以一条路走完后,就要回复以前的状态哦,免得影响另外一条路..我觉得尽管他们都说是暴力,但是我觉得这个题还是蛮好的... 题目: F.

Codeforces Round #279 (Div. 2) 解题报告

A - Team Olympiad 贪心水题..都从第一个开始取即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map

Codeforces Round #279 (Div. 2) 题解集合

终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心什么的乱搞,貌似放A题难了 1 #include <cstdio> 2 #include <algorithm> 3 4 using namespace std; 5 const int N = 5005; 6 7 int cnt[5], first[5], next[N]; 8 9