zoukankan      html  css  js  c++  java
  • Codeforces 435 A Queue on Bus Stop

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

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

    不过写出来不对

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

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 const int INF = (1<<30)-1;
    15 const int mod=1000000007;
    16 const int maxn=100005;
    17 int a[maxn],used[maxn];
    18 
    19 int main(){
    20     int n,m;
    21     scanf("%d %d",&n,&m);
    22     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    23     
    24     int left=0;
    25     int ans=0;
    26     for(int i=1;i<=n;i++){
    27         if(a[i]>left){
    28             ans++;
    29             left=m-a[i];
    30         }
    31         else 
    32         if (a[i]<=left) left-=a[i];
    33     //    printf("left=%d
    ",left);
    34     }
    35     printf("%d
    ",ans);
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    资产置换
    《CSS3使用指南》读书笔记
    foxtable使用笔记
    Java语法糖
    IO笔记
    HttpClient使用笔记
    正则表达式之?(问号)的使用
    关于HTML代码的转义
    《大数据时代》读书笔记
    《自己动手写网络爬虫》读书笔记
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4442917.html
Copyright © 2011-2022 走看看