Codeforces Round #249 (Div. 2) A题
1 second
256 megabytes
standard input
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.
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).
Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.
4 3
2 3 2 1
3
3 4
1 2 1
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题的更多相关文章
- Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!
http://codeforces.com/contest/435/problem/C
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- 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 ...
- 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 ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- Codeforces Round #425 (Div. 2))——A题&&B题&&D题
A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...
随机推荐
- 【python cookbook】【字符串与文本】3.利用shell通配符做字符串匹配
问题:当工作在Linux shell下时,使用常见的通配符模式(即,*.py.Dat[0-9]*.csv等)来对文本做匹配 解决方案:fnmatch模块提供的两个函数fnmatch().fnmatch ...
- TI CC2541的中断优先级设置.
实际看到的中断优先级设置是这样的:
- Android消息处理机制(Handler 与Message)---01
一.handler的使用场景为么会有handler?(部分内容图片摘自http://www.runoob.com/w3cnote/android-tutorial-handler-message.ht ...
- PHP过滤评论关键词
<?php /** * PHP中屏蔽过滤指定关键字实现方法总结 * http://www.111cn.net/phper/phpanqn/46225.htm * * 思路: * 一.把关键字专门 ...
- PullToRefresh 下拉刷新的样式修改
资源文件结构图, 先看看下拉刷新头的布局, <?xml version="1.0" encoding="utf-8"?> <merge xml ...
- Git and GitHub
1.GitHub 创建一个仓库 2.进入本地要管理的某个文件夹下,感觉目录的操作命令和linux里面差不多, $git init 此时该文件下就会多出一个.git的文件 3.进入要上传的仓库,右键gi ...
- ACM题目————图的广度优先搜索
题目描述 图的广度优先搜索类似于树的按层次遍历,即从某个结点开始,先访问该结点,然后访问该结点的所有邻接点,再依次访问各邻接 点的邻接点.如此进行下去,直到所有的结点都访问为止.在该题中,假定所有的结 ...
- MongoDB在windows自启动
D:\mongodb\Server\3.0\bin>mongod --logpath D:\mongodb\log\mongo.log --logappend--dbpath D:\mongod ...
- 【转】Tomcat中部署java web应用程序
http://www.blogjava.net/jiafang83/archive/2009/06/02/279644.html 转载:今天给大家介绍怎样在Tomcat5.5.9中部署Java Web ...
- android 代码整体回退
repo forall -c 'HAHA=`git log --before="3 days" -1 --pretty=format:"%H"`;git res ...