A. Queue on Bus Stop
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.

The bus stop queue has n groups of people. The i-th group from the beginning has ai people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.

Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ m).

Output

Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.

Sample test(s)
input
4 3
2 3 2 1
output
3
input
3 4
1 2 1
output
1
模拟题……没啥好说的。贴代码:
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define inf 0x7fffffff
#define LL long long
#define read fastreading()
inline int fastreading()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int a[1000];
int n,m,ans,s;
int main()
{
n=read;
m=read;
for (int i=1;i<=n;i++)
{a[i]=read;if (a[i]+s<=m) {s+=a[i];}else {ans++;s=a[i];}if (a[i]==m){ans++;s=0;}}
if (s) ans++;
cout<<ans;
}

cf435A Queue on Bus Stop的更多相关文章

  1. Codeforces 435 A Queue on Bus Stop

    题意:给出n队人坐车,车每次只能装载m人,并且同一队的人必须坐同一辆车,问最少需要多少辆车 自己写的时候想的是从前往后扫,看多少队的人的和小于m为同一辆车,再接着扫 不过写出来不对 后来发现把每一队的 ...

  2. Codeforces Round #249 (Div. 2) A - Queue on Bus Stop

    水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...

  3. Codeforces Round #249 (Div. 2) A题

    链接:http://codeforces.com/contest/435/problem/A   A. Queue on Bus Stop time limit per test 1 second m ...

  4. IEEE 802

    IEEE 802又称为LMSC(LAN /MAN Standards Committee, 局域网/城域网标准委员会), 致力于研究局域网和城域网的物理层和MAC层中定义的服务和协议, 对应OSI网络 ...

  5. TCP/IP协议原理与应用笔记10:TCP/IP协议族

    1. 协议族视图如下:(这里我们列举重要的,并不是所有的) (1)网络接入层(数据链路层 和 物理层): 通过接入的物理网络的 功能 和 覆盖范围 进行分析划分为: •LANs :局域网(Local ...

  6. NOIP(划掉)CSP2019一轮知识点

    今年似乎变动很大呢…… 去年总结的 历年真题 以下标题中打*的是我认为的重点内容 *一.关于计算机 (一)计算机组成 计算机的工作原理跟人的大脑很相似,而且还是大脑功能的延伸,所以习惯上叫它电脑. 硬 ...

  7. 利用Service bus中的queue中转消息

    有需求就有对策就有市场. 由于公司global的policy,导致对公司外发邮件的service必须要绑定到固定的ip地址,所以别的程序需要调用发邮件程序时,问题就来了,如何在azure上跨servi ...

  8. Windows Azure Service Bus (2) 队列(Queue)入门

    <Windows Azure Platform 系列文章目录> Service Bus 队列(Queue) Service Bus的Queue非常适合分布式应用.当使用Service Bu ...

  9. Windows Azure Service Bus (3) 队列(Queue) 使用VS2013开发Service Bus Queue

    <Windows Azure Platform 系列文章目录> 在之前的Azure Service Bus中,我们已经介绍了Service Bus 队列(Queue)的基本概念. 在本章中 ...

随机推荐

  1. Com原理及應用——Com對象和接口

    1.COM对象的理解 COM对象类似于C++语言中类的概念,类的每个实例代表一个COM对象,它也包括属性(即状态)和方法(即操作),状态反映对象的存在,方法就是接口. 2.COM对象的标识-CLSID ...

  2. @余凯_西二旗民工 【SVM之菜鸟实现】—5步SVM

    #翻译#了下 余凯老师的 心法 以前的一篇博文:二分类SVM方法Matlab实现 前几日实现了下,虽然说是Linear-SVM,但是只要可以有映射函数也可以做kernel-svm function [ ...

  3. 让jquery easyui datagrid列支持绑定嵌套对象

    嵌套对象是指返回的json数据,是对象的某个属性自带有属性.而我们恰恰又需要这个属性,默认情况下easyui的datagrid是不支持绑定嵌套对象的.比如:datagrid的field属性只能为fie ...

  4. 最小生成树--->NYOJ-38 布线问题

    此题是最基础的最小生成树的题目,有两种方法, 一个是prim一个是kruskal算法,前者利用邻接矩阵,后者是利用边集数组 prim算法的思想是:一个点一个点的找, 先找从第一个点到其他点最小的, 把 ...

  5. C# 面向对象 , 继承

    继承 class A { Console.WriteLine("hello world"); } class B:A { } 以上书写,表示B 是A 的子类,  B 同时继承A 中 ...

  6. 关于ASP.Net 4.0的ClientID

    我们知道因为在原来的ASP.NET应用程序中使用服务端控件在生成ClientID的时,是很难控制的,特别是在嵌套的控件的时候,比如在多个嵌套Repeater中要控制某一个控件生成的html的ID属性, ...

  7. An attempt to attach an auto-named database for file

    在用VS自带的 .mdf读取(joint)时,报错: Server Error in '/' Application. An attempt to attach an auto-named datab ...

  8. UVA 305 Joseph (约瑟夫环 打表)

     Joseph  The Joseph's problem is notoriously known. For those who are not familiar with the original ...

  9. Delphi XE5 附破解补丁

    Embarcadero RAD Studio XE5 Version 19.0.13476.4176: http://altd.embarcadero.com/download/radstudio/x ...

  10. 【结构型】Proxy模式

    代理模式是指为其他对象提供代理来控制对象的访问.这种手段有时候可以给我们带来许多好处.如:通过代理可以实现异步响应处理:通过代理可以起到保护或限制对象的使用的作用,从而提高安全性. 在设计上,用户使用 ...