• codeforces 677B B. Vanya and Food Processor(模拟)


    题目链接:

    B. Vanya and Food Processor

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed hand the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.

    Vanya has n pieces of potato, the height of the i-th piece is equal to ai. He puts them in the food processor one by one starting from the piece number 1 and finishing with piece number n. Formally, each second the following happens:

    1. If there is at least one piece of potato remaining, Vanya puts them in the processor one by one, until there is not enough space for the next piece.
    2. Processor smashes k centimeters of potato (or just everything that is inside).

    Provided the information about the parameter of the food processor and the size of each potato in a row, compute how long will it take for all the potato to become smashed.

     
    Input
     

    The first line of the input contains integers nh and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ h ≤ 109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.

    The second line contains n integers ai (1 ≤ ai ≤ h) — the heights of the pieces.

     
    Output
     

    Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.

     
    Examples
     
    input
    5 6 3
    5 4 3 2 1
    output
    5
    input
    5 6 3
    5 5 5 5 5
    output
    10
    input
    5 6 3
    1 2 1 1 1
    output
    2

    题意:

    有这么多高为a[i]的土豆,每次最多放h高度的土豆,超过了就不能放进去了,每秒削k高度的,问这些得用多长时间;

    思路

    模拟削土豆的过程算一下时间就好了;

    AC代码:
    #include <bits/stdc++.h>
    /*#include <vector>
    #include <iostream>
    #include <queue>
    #include <cmath>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    */
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const LL inf=1e10;
    const int N=1e5+15;
    
    int n,h,k;
    int a[N];
    int main()
    {
        read(n);read(h);read(k);
        Riep(n)read(a[i]);
        LL ans=0,sum=0;
        Riep(n)
        {
            if(sum+a[i]>h)
            {
                if(sum%k==0)ans=ans+sum/k;
                else ans=ans+sum/k+1;
                ans=ans+a[i]/k;
                sum=a[i]%k;
            }
            else
            {
                sum=sum+a[i];
                ans=ans+sum/k;
                sum=sum%k;
            }
        }
        if(sum>0)ans++;
    print(ans);
        return 0;
    }



  • 相关阅读:
    15. 驱动通用编译脚本
    13. linux 中断式驱动编程
    vlc源码分析(二) 播放流程
    vlc源码分析(一) vlc-android native调试配置
    RTSP会话流程——理论结合例子,非常具有参考意义
    RTSP协议学习笔记——详细总纲,入门圣典
    VLC源码分析总结 ——入门纲领
    如何阅读X264代码
    源码分析系列(五)x264_ratecontrol_dataflow
    源码分析系列(四)x264_nal_dataflow
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5551909.html
Copyright © 2020-2023  润新知