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 ...
随机推荐
- iOS - 代码查看控制台打印内存使用情况:
1.先导入: #import <mach/mach.h> 2.写此方法.单位为兆(M). void report_memory(void) { struct task_basic_info ...
- 试用版SQL Server 2008 R2 提示评估期已过
解决SQL Server 2008提示评估期已过第一步:进入SQL2008配置工具中的安装中心第二步:再进入维护界面,选择版本升级第三步:进入产品密钥,输入密钥第四步:一直点下一步,直到升级完毕.SQ ...
- Backup: Numbers in Perl6
Perl6 is a new language, not a improved version of Perl5. Perl6 inherits many good features from man ...
- oracle初次使用连接不上
问题描述: win10下,cmd运行 输入sqlplus报一下错误 SP2-1503: 无法初始化 Oracle 调用界面 SP2-0152: ORACLE 不能正常工作 解决办法 cmd右键--以管 ...
- SQL中char、varchar、nvarchar的区别
char char是定长的,也就是当你输入的字符小于你指定的数目时,char(8),你输入的字符小于8时,它会再后面补空值.当你输入的字符大于指定的数时,它会截取超出的字符. nvarcha ...
- linux正则表达式使用
首先介绍下正则表达式,它是由一串字符和元字符构成的字符串,简称RE(Regular Expression),它的主要功能是文本查询和字符串操作,它可以匹配一个文本的字符和字符集,达到数据过滤的效果. ...
- ACM题目————图的广度优先搜索
题目描述 图的广度优先搜索类似于树的按层次遍历,即从某个结点开始,先访问该结点,然后访问该结点的所有邻接点,再依次访问各邻接 点的邻接点.如此进行下去,直到所有的结点都访问为止.在该题中,假定所有的结 ...
- 【转】在Eclipse中配置tomcat
转载地址: http://kin111.blog.51cto.com/738881/163096 为了在Eclipse中进行struts2的测试,才发现自己机器上的Eclipse没有集成Tomcat, ...
- poj1785 Binary Search Heap Construction
此题可以先排序再用rmq递归解决. 当然可以用treap. http://poj.org/problem?id=1785 #include <cstdio> #include <cs ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...