zoukankan      html  css  js  c++  java
  • AIM Tech Round 3 (Div. 2) A

    Description

    Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.

    The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

    Input

    The first line of the input contains three integers nb and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.

    The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

    Output

    Print one integer — the number of times Kolya will have to empty the waste section.

    Examples
    input
    2 7 10
    5 6
    output
    1
    input
    1 5 10
    7
    output
    0
    input
    3 10 10
    5 7 7
    output
    1
    input
    1 1 1
    1
    output
    0
    Note

    In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.

    In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

    题意:就是给你n个水果,有台榨汁机(最多一次性只能装b大小的水果,容量是d),如果超过容量就清理一次。问你要清理几次

    解法:模拟,超过大小的可以不要,相加的和超过容量的就清零,num+1

    #include<bits/stdc++.h>
    using namespace std;
    long long a[100005],b,d;
    int main()
    {
        int n;
        long long  sum=0;
        long long  num=0;
        cin>>n>>b>>d;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]<=b)
            {
                sum+=a[i];
            }
            else
            {
                continue;
            }
            if(sum>d)
            {
                sum=0;
                num++;
            }
        }
        cout<<num<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    Linux下运行java项目
    Matlab 绘图完整入门
    Matlab命令合集 妈妈再也不用担心我不会用matlab了
    详尽全面的matlab绘图教程
    拉格朗日乘子法 那些年学过的高数
    【转】几款网络仿真软件的比较
    正则表达式30分钟入门教程 ——堪称网上能找到的最好的正则式入门教程
    并发编程详细整理
    高并发通信模型NIO
    Java并发编程的艺术笔记(九)——FutureTask详解
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5910863.html
Copyright © 2011-2022 走看看