CodeForces 279B Books
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的更多相关文章
- CodeForces 279B Books (滑动窗口)
题意:给定n本书的阅读时间,然后你从第 i 本开始阅读,问你最多能看多少本书在给定时间内. 析:就是一个滑动窗口的水题. 代码如下: #pragma comment(linker, "/ST ...
- Codeforces 278B Books
好久没有写二分了 题意:有n本书 每本书有一个阅读时间ai 要在t时间内读最多的书 读书的顺序是连续的,如果无法读完一本书就不能开始 最开始觉得会是个dp,但是动规方程写不出来.想想会不会是二分呢,也 ...
- codeforces279B
Books CodeForces - 279B When Valera has got some free time, he goes to the library to read some book ...
- 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 ...
- 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. ...
- 数学 Codeforces Round #308 (Div. 2) B. Vanya and Books
题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...
- 【33.33%】【codeforces 552B】Vanya and Books
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 ...
- CodeForces - 1214D B2. Books Exchange (hard version)
题目链接:http://codeforces.com/problemset/problem/1249/B2 思路:用并查集模拟链表,把关系串联起来,如果成环,则满足题意.之后再用并查集合并一个链,一个 ...
随机推荐
- 第五十篇、OC中常用的第三插件
1.UIViewController-Swizzled 当你接手一个新项目的时候,使用该插件,可以看到控制器的走向,当前控制是哪个,下一个跳转到哪里 2. 一个Xcode小插件,将Json直接转成模型 ...
- margin的重叠现象
当两个相邻的普通元素设置margin时,则它们的间距并不是简单的外边距相加. <!DOCTYPE html> <html lang="en"> <he ...
- [Bootstrap]全局样式(五)
辅助样式 1.情景文本色 .text-muted .text-primary .text-success .text-info .text-warning .text-danger {c ...
- apache和php扩展问题
1.redis扩展: windows下开发用的xampp集成的环境,想装个php-redis扩展,扩展的github地址: https://github.com/nicolasff/phpredis ...
- TreeView递归绑定数据的两种方法
#region 绑定TreeView /// <summary> /// 绑定TreeView(利用TreeNode) /// </summary> /// <param ...
- ASP.NET 将DataTable解析成JSON简介
这里解析json使用的是Newtonsoft.Json.dll程序集.下面请看code: using System; using System.Collections.Generic; using S ...
- DIV当textarea使用,在聚焦的时候将光标移动到内容的末尾
#### DIV当textarea使用,在聚焦的时候将光标移动到内容的末尾 #### <style type="text/css"> .test_box { width ...
- select&pselect/poll&ppoll/epoll
select/pselect, poll和epoll的区别 select,epoll,poll比较 select,poll,epoll进化 Handling of asynchronous event ...
- flex打印图片
<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication xmlns:fx=& ...
- mac 下 sphinx + mysql + php 实现全文搜索(xampp)(1)
原理: 使用sphinx 中的indexer 生成索引数据 service/web 端 利用searched 调用索引数据 步骤: 下载 sphinx: 下载地址:http://sphinxsea ...