题意:给出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. 创建本地yum源及grouplist 出错

    RHEL有时候使用自定义的YUM源是很方便的事情. yum install createrepo createrepo /your/repo/directory/ 不过由于粗心,本人在使用时遇到很郁闷 ...

  2. Subclasses

    Given a collection of numbers, return all possible subclasses. public class Solution { public List&l ...

  3. (转)xmpp 环境配置-支持扩展

    第一种方法直接拖 1> 拖入文件夹 在网盘链接的xmppFramework文件夹 :http://pan.baidu.com/s/1jGxLa3G 也可以直接去github搜索下载. 2> ...

  4. POJ 2075

    #include<iostream> #include<stdio.h> #include<string> #include<map> #include ...

  5. C# 匿名方法 1027

    class Program { static void Main(string[] args) { SorAndShowFiles("Sorted by name", delega ...

  6. Spring mvc json null

    http://blog.csdn.net/zdsdiablo/article/details/9429263

  7. 编程实现Linux下的ls -l

    头文件 #ifndef __FUNC_H__ #define __FUNC_H__ #include <stdio.h> #include <stdlib.h> #includ ...

  8. maven本地仓库.m2文件夹路径讲解

    Maven是一个项目管理工具,它包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目生命周期(Project Lifecycle),一个依赖管理系统(Depen ...

  9. Tomcat SSL 设置

    1. 先用如下命令生成tomcat 证书 cls rem please set the env JAVA_HOME before run this bat file SET JAVA_HOME=C:\ ...

  10. Hibernate笔记——(ONE TO ONE)一对一

    转自:http://ryxxlong.iteye.com/blog/622652 ================= 一对一(one-to-one)实例(Person-IdCard) 一对一的关系在数 ...