链接:http://codeforces.com/contest/435/problem/A
 
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

00000000000000000000000000000000000000000000000000000000000000
题意是说几伙人上公交车,每一辆公交车都有限载的量,且,每一伙人如果不能全部上车就等下一辆
问需要多少量车
 #include <stdio.h>
#include <string.h>
#include <stdlib.h> int main()
{
int n,m,i,j;
int str[];
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=; i<n; i++)
scanf("%d",&str[i]);
int bus=,mark;
for(i=; i<n; i++)
{
if(str[i] == m)
bus++;
else
{
int sum=str[i];
//mark=i;
for(j=i+; j<n; j++)
{
sum += str[j];
if(sum == m)
{
//j--;
i=j;
bus++;
sum=;
break;
}
if(sum > m)
{
j--;
i=j;
bus++;
sum=;
break;
}
}
if(i == n- && sum > )
bus++;
}
}
printf("%d\n",bus);
}
}

Codeforces Round #249 (Div. 2) A题的更多相关文章

  1. Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!

    http://codeforces.com/contest/435/problem/C

  2. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

  3. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  4. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  5. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  6. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  7. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  8. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  9. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

随机推荐

  1. 不小心rm删除文件怎么办

    不小心rm删除文件怎么办 rm 命令的副作用越来越显现.而且rm掉之后的东西想找回来很困难.有2个原则: 1 永远不要在root下操作,尤其是rm命令 2 写一个别名,代替rm 我就是在~/.bash ...

  2. linux文件所属用户和组

    使用chown命令可以修改文件或目录所属的用户: 命令:chown 用户 目录或文件名 例如:chown -R qq /home/qq  (把home目录下的qq目录的拥有者改为qq用户) 使用chg ...

  3. 获取url中的参数\+发送ajax请求根路径|+获取复选框的值

    //获取url中的参数function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=( ...

  4. 慎用MySQL replace语句

    语法: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [PARTITION (partition_name,...)] [(col_name,... ...

  5. AVAudioplayer时error解决 创建失败 ERror creating player: Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"

    AVAudioplayer 有两个初始化方法: 1.[[AVAudioPlayer alloc] initWithData:musicData error&e]; 2.[[AVAudioPla ...

  6. satis 搭建 Composer 私有库的方法

    安装 satis 命令行下执行: php create-project composer/satis --stability=dev --keep-vcs . 配置 创建 satis.json 文件, ...

  7. C#:文件、文件夹特别操作

    1.过滤特殊字符 public class CharService:IDisposable { private List<char> _invalidChars; public CharS ...

  8. Prince2的七大原则(5)

    [Prince2科普]Prince2的七大原则(5) 按照惯例我们先来回顾一下,PRINCE2七大原则分别是指:持续的业务验证,经验学习,角色与责任,按阶段管理,例外管理,关注产品,剪裁. 第五个原则 ...

  9. 关于easyui的窗口和tab页面不执行js说明

    一直以来群里里面很多人反应,在用tab加载界面的时候,界面里面的js不会执行.今天GodSon在此说明一下原因. 不管是window,dailog还是tab其实质最终都是继承了panel.panel有 ...

  10. Boring count(字符串处理)

    Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...