题意:给出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. 用 VIPER 构建 iOS 应用架构(2)

    [编者按]本篇文章由 Jeff Gilbert 和 Conrad Stoll 共同编写,通过构建一个基础示例应用,深入了解 VIPER,并从视图.交互器等多个部件理清 VIPER 的整体布局及思路.通 ...

  2. 制作类似DataGrid自定义控件

    首先看一下.net自带的DataGrid,想想如何应该怎样才能实现那样的展现形式. 1)需要以网格形式显示内容. 2)网格的宽度.高度可以定义. 3)可以显示滚动条. 4)单击可以选中某个单元格. 当 ...

  3. React.js 样式组件:React Style

    点这里 React Style 是 React.js 可维护的样式组件.使用 React Native StyleSheet.create一样的样式. 完全使用 JavaScript 定义样式: ? ...

  4. 牛 JQuery视频笔记

    QX3GLL 包装集 next() nextAll() nextAll("div"); prev();prevAll() end();andSlf(); eq(2);gt(1);l ...

  5. VMware 11 设置U盘启动,总是找不到physicalDrive1

    问题:VMware 11 设置U盘启动,总是找不到physicalDrive1 先说一下U盘启动的设置:如图 解决方案: 有两个服务没有进行启动,VMware USB Arbitration Serv ...

  6. 2014多校第二场1011 || HDU 4882 ZCC Loves Codefires (贪心)

    题目链接 题意 : 给出n个问题,每个问题有两个参数,一个ei(所要耗费的时间),一个ki(能得到的score).每道问题需要耗费:(当前耗费的时间)*ki,问怎样组合问题的处理顺序可以使得耗费达到最 ...

  7. OnClientClick="return confirm('确定要删除吗?')"

    OnClientClick="return confirm('确定要删除吗?')"   -----------------------前台代码 OnClientClick用于执行客 ...

  8. http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html

    http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html

  9. 跨平台 c 开发库 tbox v1.6.0,支持跨平台协程

    http://www.oschina.net/news/78582/tbox-v-1-6-0

  10. 12个QT基本对话框,以及淡入原理(用定时器把窗口逐渐变成透明)

    一.基本对话框 1,核心库: 界面程序 QApplication 非程序界面QCoreAppliction 2,消息循环必须执行QApplication.exec(); 3,消息绑定机制: 信号-槽  ...