Codeforces 435 A Queue on Bus Stop
题意:给出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的更多相关文章
- cf435A Queue on Bus Stop
A. Queue on Bus Stop time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces 28C Bath Queue 【计数类DP】*
Codeforces 28C Bath Queue LINK 简要题意:有 n 个人等概率随机进入 m 个房间,一个房间可以有多个人,第 i 个房间有 ai 个水龙头,在一个房间的人要去排队装水,他们 ...
- Codeforces Round #249 (Div. 2) A - Queue on Bus Stop
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- 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 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- codeforces 660B B. Seating On Bus(模拟)
题目链接: B. Seating On Bus time limit per test 1 second memory limit per test 256 megabytes input stand ...
- codeforces 435 B. Pasha Maximizes 解题报告
题目链接:http://codeforces.com/problemset/problem/435/B 题目意思:给出一个最多为18位的数,可以通过对相邻两个数字进行交换,最多交换 k 次,问交换 k ...
- Codeforces 435 B Pasha Maximizes【贪心】
题意:给出一串数字,给出k次交换,每次交换只能交换相邻的两个数,问最多经过k次交换,能够得到的最大的一串数字 从第一个数字往后找k个位置,找出最大的,往前面交换 有思路,可是没有写出代码来---sad ...
- CodeForces 767B The Queue
模拟. 情况有点多,需要仔细.另外感觉题目的$tf$有点不太对......而且数据水了. $0$ $5$ $2$ $2$ $0$ $5$ 这组数据按照题意的话答案可以是$2$和$4$,但是好多错的答案 ...
随机推荐
- ssh 远程 centos 乱码
今天,帮我们同学处理一下中文显示乱码的问题.这个是个国内Linux用户烦恼的问题,由于大部分的Linux发行版都是以英语为主体的,而且英文在通用性和稳定性上都比中文要好一些,各种奇怪的BUG也要少一点 ...
- JAVA非空条件三元运算符
//非空情况处理: // Integer holidayPrice = order.get("holidayPrice")!=null?Integer.valueOf(String ...
- c#实现串口操作 SerialPort
命名空间:using System.IO.Ports;该类提供了同步 I/O 和事件驱动的 I/O.对管脚和中断状态的访问以及对串行驱动程序属性的访问. 操作类声明: SerialPort sp = ...
- OPEN资讯
http://www.open-open.com/news/view/1f55540 随着 Android 平台市场份额的持续猛增 , 越来越多的开发者开始投入 Android 应用程序的开发大潮.如 ...
- ExtJs之Ext.util.TaskRunner
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- hdu 3658 How many words
思路: 构造矩阵,矩阵快速幂!!! 代码如下: #include<cstdio> #include<vector> #include<cmath> #include ...
- C# DES 加密 解密
//注意:密钥必须为8位 private const string m_strEncryptKey = "abcd1234"; /// <summary> /// 加密 ...
- 李洪强iOS开发之下载
// // // LHQDownLoader.m // A21 - 李洪强 - 下载 // // Created by vic fan on 16/7/3. // Copyright © 20 ...
- Linux下Boost交叉编译
http://davidlwq.iteye.com/blog/1580752 运行环境:ubuntu 12.04, boost 1.50.0 由于要把boost移植到arm板上去,所以折腾了一下,后来 ...
- 一个简单的ObjC和JavaScript交互工具
https://github.com/changjianfeishui/XBWebBridge ObjectiveC与Js交互是常见的需求,可对于新手或者所谓的高手而言,其实并不是那么简单明了.这里只 ...