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. iOS开发常用国外网站清单

    工欲善其事必先利其器,最近发现临时查找一些东西容易浪费时间,花了点时间整理一下常用的网站,方便以后备用. 国内的code4app,ui4app,cocoachina,oschina,csdn就不说了, ...

  2. 《JAVA课程设计》实训第四天——《猜猜看》游戏

    第四天,本来想进一步去改进<猜猜看>游戏的.可是非常多问题都不理解.也不熟悉怎么去弄到连接数据库.统计猜对次数,所以并没有进行再多的改动. 基本上就是这种执行结果了 import java ...

  3. lamp安装指南(转)

    主要软件包, 1. httpd-2.2.6.tar.gz 2. mysql-5.0.45-linux-i686-glibc23.tar.gz ( 这个版本是已编译好的压缩包,解压后稍做配置即可使用 ) ...

  4. 跨平台传输中使用base64来保证非ascii码字符串的完整性

    首先,我们来看一个例子: byte[] b=new byte[]{2,9,43}; String ss=new String(b,"utf-8"); byte[] b1=ss.ge ...

  5. php function_name($type=0,$order_ids='',$flag=2)

    $order_ids='',表示$order_ids是字符串,不是数组 foreach ($order_ids as $key=>$order_id){            //TODO} 这 ...

  6. Xml序列化自引用/循环引用问题2

    1.类定义: public class Student { public int ID { get; set; } public string Name { get; set; } //[XmlIgn ...

  7. 怎样成为PHP 方向的一个合格的架构师

    突然看到这篇文章, 值得反省, 乐在其中, 在接下来的发展中不被淘汰的都来看看, 如何成为一个架构师先明确这里所指的PHP工程师,是指主要以PHP进行Web系统的开发,没有使用其的语言工作过.工作经验 ...

  8. [php基础]记录PHP错误日志 display_errors与log_errors的区别

    display_errors 错误回显,一般常用语开发模式,但是很多应用在正式环境中也忘记了关闭此选项.错误回显可以暴露出非常多的敏感信息,为攻击者下一步攻击提供便利.推荐关闭此选项. display ...

  9. WPF画N角芒星,正N角星

    计算顶部三角形坐标方法: /// <summary> /// 获取顶三角形坐标 /// </summary> /// <param name="r"& ...

  10. java2实用教程102小程序(分数计算和流水线计算

    import java.util.Scanner; public class test{ public static void main(String args[]){ Rational a=new ...