Problem C:松果( cone)
来源:互联网 发布:数据挖掘跟gis的关系 编辑:程序博客网 时间:2024/04/29 07:25
Problem C:松果( cone)
Time Limit:1000MS Memory Limit:65536K
Total Submit:44 Accepted:27
Description
【题目描述】
大森林有熊兄弟的好朋友松鼠蹦蹦,一天蹦蹦来到一条很长的小 路, 发现沿路地上都有松果,高兴极了,决定尽可能多吃松果。 蹦蹦观察到,每个松果的重量并不一定相同,可蹦蹦的肚子容量 有限,总共最多只能吃重量 C 的松果。 蹦蹦吃东西有个特点,一旦开吃就会不停的吃,不会漏过路上碰 到松果, 直到遇到一个吃不下或吃完停止。 也就是说松鼠蹦蹦只会吃 连续一段的松果。 已知路上共有 N 个松果,顺序的重量是 w1,w2,….wn。 蹦蹦最多 可能吃多少颗松果?
【输入格式】
第一行,二个正整数,空格分开,表示 N 和 C,N 范围在[1..50000], C 范围在[1..1000000]。 第二行, N 个正整数,空格分开,表示从 w1、 w2,…wn, 即松果的重量。每个松果重 量范围在[1..1000]。
【输出格式】
一个正整数, 蹦蹦可以吃到的最多松果数量。
输入样例
9 5 1 5 4 3 2 1 1 4 1
输出样例
3
Input
Output
Sample Input
Sample Output
#include<iostream>#include<cstdio>#include<cmath>using namespace std;int a[1000000+10];int main(){int n,c,high=1,low=1,sum=0,ans=-1;cin>>n>>c;for(int i=1;i<=n;i++) scanf("%d",&a[i]);while(high<=n){while(high<=n&&sum<=c){sum+=a[high];high++;if(sum<=c) ans = max(high-low,ans);}while(low<=n&&sum>c){sum-=a[low];low++;}}cout<<ans;return 0;}
阅读全文
0 0
- Problem C:松果( cone)
- 松果
- 松果
- 回收锥(recession cone)
- [SMOJ1725]松果
- 一场呆萌的小动物大战,抢劫松果店(The Nut Job)
- 【smoj 1167】松果
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem C
- Problem c
- Problem C
- Problem C
- Problem C
- Problem C
- 难以支付解题报告
- Problem A:队伍(team)
- Linux 常用性能分析命令
- IP地址相关知识
- springmvc之视图定位
- Problem C:松果( cone)
- mybatis开发原始dao的方式
- AngularJS 入门4-表单和验证
- 最近做的一些事的复盘
- ViewPager系列之-仿掌上英雄联盟皮肤浏览效果
- GLSL记录(1)-实时旋转的三角形
- python3 矩阵的切片
- for循环正确遍历数组
- 数据库连接池