题意:给出n队人坐车,车每次只能装载m人,并且同一队的人必须坐同一辆车,问最少需要多少辆车

自己写的时候想的是从前往后扫,看多少队的人的和小于m为同一辆车,再接着扫

不过写出来不对

后来发现把每一队的人装走之后,储存下这辆车还能装载的人数,每一次再判断

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
int a[maxn],used[maxn]; int main(){
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]); int left=;
int ans=;
for(int i=;i<=n;i++){
if(a[i]>left){
ans++;
left=m-a[i];
}
else
if (a[i]<=left) left-=a[i];
// printf("left=%d\n",left);
}
printf("%d\n",ans);
return ;
}

Codeforces 435 A Queue on Bus Stop的更多相关文章

  1. cf435A Queue on Bus Stop

      A. Queue on Bus Stop time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces 28C Bath Queue 【计数类DP】*

    Codeforces 28C Bath Queue LINK 简要题意:有 n 个人等概率随机进入 m 个房间,一个房间可以有多个人,第 i 个房间有 ai 个水龙头,在一个房间的人要去排队装水,他们 ...

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

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

  4. Educational Codeforces Round 11B. Seating On Bus 模拟

    地址:http://codeforces.com/contest/660/problem/B 题目: B. Seating On Bus time limit per test 1 second me ...

  5. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. codeforces 660B B. Seating On Bus(模拟)

    题目链接: B. Seating On Bus time limit per test 1 second memory limit per test 256 megabytes input stand ...

  7. codeforces 435 B. Pasha Maximizes 解题报告

    题目链接:http://codeforces.com/problemset/problem/435/B 题目意思:给出一个最多为18位的数,可以通过对相邻两个数字进行交换,最多交换 k 次,问交换 k ...

  8. Codeforces 435 B Pasha Maximizes【贪心】

    题意:给出一串数字,给出k次交换,每次交换只能交换相邻的两个数,问最多经过k次交换,能够得到的最大的一串数字 从第一个数字往后找k个位置,找出最大的,往前面交换 有思路,可是没有写出代码来---sad ...

  9. CodeForces 767B The Queue

    模拟. 情况有点多,需要仔细.另外感觉题目的$tf$有点不太对......而且数据水了. $0$ $5$ $2$ $2$ $0$ $5$ 这组数据按照题意的话答案可以是$2$和$4$,但是好多错的答案 ...

随机推荐

  1. Sqli-labs less 30

    Less-30 Less-30与less-29原理是一致的,我们可以看到less-30的sql语句为: 所以payload为: http://127.0.0.1:8080/sqli-labs/Less ...

  2. Grid分组特性

    Ext.onReady(function () {                Ext.define('personInfo', {                    extend: 'Ext. ...

  3. ThinkPHP3.2 分页实现

    ThinkPHP 分页实现   TP3.2框架手册,有一个数据分页,不过每次都要写太多的代码,还有中文设置等有些麻烦,做为程序开发者,有必要整理下: O.先看效果图 一.分页方法 /** * TODO ...

  4. 翻译 - NodeJS错误处理最佳实践

    王龑 - APRIL 13, 2015 NodeJS的错误处理让人痛苦,在很长的一段时间里,大量的错误被放任不管.但是要想建立一个健壮的Node.js程序就必须正确的处理这些错误,而且这并不难学.如果 ...

  5. Dungeon Game

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  6. android模拟器(genymotion)+appium+python 框架执行过程中问题解答

    1.case运行过程中中文输入不进去? 答:注意事项 1)需要修改系统编码为utf-8,才能解决中文输入问题,case执行入口文件添加代码如下: import sys reload(sys) sys. ...

  7. sublime3可用key

    —– BEGIN LICENSE —–Nicolas HennionSingle User LicenseEA7E-8660758A01AA83 1D668D24 4484AEBC 3B04512C8 ...

  8. 计算机学院2014年“新生杯”ACM程序设计大赛

    1440: 棋盘摆车问题 对于输入n,k: 1.当n<k时,无满足的摆法 2.否则 第一个车可以排n*n个位置(即整个棋盘),第二个可排(n-1)*(n-1)个位置,…… 正如排列组合一样,车与 ...

  9. libevent简单介绍

    http://blog.csdn.net/mafuli007/article/details/7476014 1      简介 主页:http://www.monkey.org/~provos/li ...

  10. C++不能显式调用构造函数,会生成匿名对象,这点与Java完全不一样!

    Java可以直接调用同名构造函数,仅仅起初始化的功能,并不构造新的对象,但是C++里面没有.看一下这段代码: class A { public: A() { printf("A() \n&q ...