zoukankan      html  css  js  c++  java
  • topcoder SRM 617 DIV2 SlimeXSlimonadeTycoon

    此题需要注意的两个地方是

    (1)在某天生产出来的Slimonades,必须在stale_limit天内必须卖完,否则超过stale_limit内抛弃(东西都有保质期)

    (2)每天生产出来的Slimonades的数量在0到morning[i]之间,而不是morning[i]

    故第i天卖的东西可能来自max(0,i-stale_limit+1)~i 之间任何一天的东西,假设j在这些天数之间,

    则第j天生产的东西在第i天卖的数量为min(morning[j], customer[i]),故遍历一遍即可

    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    class SlimeXSlimonadeTycoon{
    public:
        int sell(vector<int> morning, vector<int> customers, int stale_limit){
            int res = 0 ;
            for(int i = 0 ; i < morning.size(); ++ i){
                for(int j = max(0,i-stale_limit+1); j<= i; ++ j){
                    if(customers[i] > 0){
                        int t = min(customers[i],morning[j]);
                        res += t;
                        customers[i] -=t;
                        morning[j] -=t;
                    }
                }
            }
            return res;
        }
    };
  • 相关阅读:
    工商银行在线支付接口
    Runtime-compiler和Runtime-only的区别:
    响应式网站技术精要总结
    ajax基础
    jquery选择器 笔记
    js数组去重的几种方法
    js中的call apply bind
    es6中的类
    bootstrap组件
    es6中的模块化输出
  • 原文地址:https://www.cnblogs.com/xiongqiangcs/p/3780977.html
Copyright © 2011-2022 走看看