题意:给出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. NET 查找程序集路径(CLR关于Assembly的搜索路径的过程)

    最近在回顾.Net应用程序的执行环境,这里做一个很小的总结,方面以后需要的时候进行查找: CLR必须可以找到正确的Assembly,Net提供了Assembly搜索算法,可以根据.config文件(类 ...

  2. NWR协议

    NWR是一种在分布式存储系统中用于控制一致性级别的一种策略.在Amazon的Dynamo云存储系统中,就应用NWR来控制一致性. 让我们先来看看这三个字母的含义:N:在分布式存储系统中,有多少份备份数 ...

  3. line-height 与垂直居中!

    在此之前,对于line-height 与垂直居中的问题,经常碰到. 比如,图片与span在同一个box中的时候,竟然会各种偏移.要想达到理想的效果真的是各种难. 有时间,决定认真的啃一啃. 一 lin ...

  4. HDU 4027 Can you answer these queries?(线段树的单点更新+区间查询)

    题目链接 题意 : 给你N个数,进行M次操作,0操作是将区间内的每一个数变成自己的平方根(整数),1操作是求区间和. 思路 :单点更新,区间查询,就是要注意在更新的时候要优化,要不然会超时,因为所有的 ...

  5. appium自动化测试中获取toast消息的解决方法【转】

    http://blog.csdn.net/hqzxsc2006/article/details/50036911 待实践.. 解决方法:appium下切换selendroid模式去获取Android的 ...

  6. Newtonsoft.Json.dll

    代码 using System; DoNet2.0 需要借助于Newtonsoft.Json.dll using System.IO; using System.Text; using Newtons ...

  7. Yarn中如何生成状态机图

    原文 http://xiguada.org/yarn_state_picture/ 在Hadoop2.0系列的版本里,采用了状态机的方式处理ResourceManager,NodeManager,Ma ...

  8. hdu 1847 Good Luck in CET-4 Everybody!(简单博弈SG)

    #include<stdio.h> #include<string.h> #define N 1010 int hash[N]; int sg[N]; void GetSG() ...

  9. VS2008 引用程序集 没有强名称 解决办法

    为项目添加强名称方法:1.右键单击项目,打开属性窗口;2.在属性窗口里选择<签名>标签,选中为程序集签名的选项,在下拉列表里选择新建 3.打开新建签名窗口,输入签名的名称密码等内容 单击确 ...

  10. Ajax实例-购物车

    一.概述 1.当添加或删除商品时,购物车会立即更新数据 2.思路: (1)建立商品类Item.java,存有商品属性name,prince,code(商品编码)等 (2)建立商品目录类Catalog. ...