http://codeforces.com/problemset/problem/279/B

题意 :Valera 有很多的空闲时间,所以他决定看书,给出n本书,编号1到n,和看每本书需要的时间,他看书是随机的,然后是连续的,从第 i 本开始看,看完了会看第i+1本,然后是第i+2本,问他在时间 t 内最多能看多少本书。

思路 :一开始没看明白题意,以为把时间排序,从小开始往里加,后来才发现人家要求的是连续的。这个就是循环从头开始加,如果时间超了,就从第一本开始往外删。

#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std ; int book[] ;
int main()
{
int n,t ;
while(scanf("%d %d",&n,&t)!=EOF)
{
for(int i = ; i < n ; i++)
scanf("%d",&book[i]) ;
int sum = , cnt = ,time = ,count = ;
for(int i = ; i < n ; i++)
{
if(time+book[i] > t)
{
time -= book[cnt] ;
cnt++ ;
i-- ;
sum--;
}
else
{
time += book[i] ;
sum++ ;
count = max(sum,count) ;
}
}
cout<<count<<endl ;
}
return ;
}

CodeForces 279B Books的更多相关文章

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

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

  2. Codeforces 278B Books

    好久没有写二分了 题意:有n本书 每本书有一个阅读时间ai 要在t时间内读最多的书 读书的顺序是连续的,如果无法读完一本书就不能开始 最开始觉得会是个dp,但是动规方程写不出来.想想会不会是二分呢,也 ...

  3. codeforces279B

    Books CodeForces - 279B When Valera has got some free time, he goes to the library to read some book ...

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

    B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

  5. CodeForces Round #515 Div.3 C. Books Queries

    http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. ...

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

    题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...

  7. 【33.33%】【codeforces 552B】Vanya and Books

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. B. Vanya and Books( Codeforces Round #308 (Div. 2) 简单题)

    B. Vanya and Books time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. CodeForces - 1214D B2. Books Exchange (hard version)

    题目链接:http://codeforces.com/problemset/problem/1249/B2 思路:用并查集模拟链表,把关系串联起来,如果成环,则满足题意.之后再用并查集合并一个链,一个 ...

随机推荐

  1. Contoso 大学 - 3 - 排序、过滤及分页

    原文 Contoso 大学 - 3 - 排序.过滤及分页 目录 Contoso 大学 - 使用 EF Code First 创建 MVC 应用 原文地址:http://www.asp.net/mvc/ ...

  2. ViewPager的简单例子

    这个例子是按照官网上的例子写的,有点抄袭的嫌疑,但是自己单独写一下会加深自己的印象. 首先是MainAcitivity.xml: <LinearLayout xmlns:android=&quo ...

  3. 翻译:如何编译 Gunz 源代码

    如何编译 Gunz 源代码 本文翻译自:How to build Gunz source code 各位好,近期 Dawson 发布了 Gunz 的源代码,所以我就来做个简单的教程,来说明如何编译 G ...

  4. Paying for upgrades, by Bob Arnson

    Following content is reprinted from here, please go to the original website for more information. Au ...

  5. 使用ckplayer搭建rtmp视频直播应用

    视频直播才有的是RTMP协议进行视频实时流传输,在这里我们用到的软件都是 adobe 公司的一个是:Flash Media Server4 另一个是flash media live encoder 这 ...

  6. GDI+ 绘图闪烁解决方法

    闲着没事,准备做一个类似于TeeChart的自定义控件,结果第一步的绘图就把我给难倒了,虽然早就知道GDI绘图的闪烁问题很坑,但是却没有想到如此之坑,折腾了两天,才找到解决方法. 首先在窗体加载的时候 ...

  7. JSON参数解析工具类

    /// <summary> /// 解析JSON参数 /// </summary> public class JSONParser { JObject jObj = null; ...

  8. VI命令删除文件所有内容

    >vi test.log >gg #光标移到第一行 >:.,$d

  9. sql新感悟(where 1 = 1)

    花了好久把YII框架看完发现一本很不错的书:SQL案例解析(清华大学出版社),看到一些比较有用的东西,感觉应该把他记录下来,看了好多页发现书中一直有 where 1=1,这样的语句,查过发现“wher ...

  10. 【python】开始python之旅

    上午开始抽空学习python,具体内容如下: (1)安装了python 2.7 (2)安装了notepad ++,安装它之前,在notepad++和Sublime Text之间纠结了一下,baidu了 ...