TopCoder----卖柠檬
1. 题目描述
Problem Statement |
|||||||||||||
| You are playing a game called Slime Tycoon.You will be selling Slimonades in this game, and your goal is to sell as many as you can. The game will consist of N game days, numbered 0 through N-1 in order.You are given two vector <int>s morning and customers with N elements each, and an int stale_limit.These represent constraints on how many Slimonades you can produce and sell, as explained below. In each game day, three things happen, in the following order:
What is the maximum total number of Slimonades that you can sell during these N days? |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
| - | morning will contain between 2 and 50 elements, inclusive. | ||||||||||||
| - | Each element of morning will be between 0 and 10000, inclusive. | ||||||||||||
| - | customers will contain the same number of elements as morning. |
||||||||||||
| - | Each element of customers will be between 0 and 10000, inclusive. | ||||||||||||
| - | stale_limit will be between 1 and N, inclusive. | ||||||||||||
Examples |
|||||||||||||
|
|||||||||||||
2. 分析
采用如下的策略,每天尽可能多地生产,并且优先卖生产日期久的。。采用一个队列。。
3. 代码
class SlimeXSlimonadeTycoon
{
public:
int sell(vector <int> morning, vector <int> customers, int stale_limit)
{
if(morning.empty()) return 0; int que[100000];
int front = 0, rear = 0;
int count(0);
for(int i=0; i<morning.size(); ++i)
{
if(front - rear == stale_limit) ++rear;
que[front++] = morning[i]; while(rear < front && customers[i] > 0)
{
if(que[rear] > customers[i]){
count += customers[i];
que[rear] -= customers[i];
break;
}
else{
count += que[rear];
customers[i] -= que[rear];
++rear;
}
}
}
return int(count) ;
}
};
TopCoder----卖柠檬的更多相关文章
- JS—实现拖拽
JS中的拖拽示例: 1)实现拖拽思路:当鼠标按下和拖拽过程中,鼠标与拖拽物体之间的相对距离保持不变 2)实现拖拽遇到的问题: 问题1:当鼠标按下移动过快时,离开了拖拽的物体时 ...
- 怎么让猫吃辣椒 转载自 xiaotie
典故: 某日,毛.周.刘三人聊天. 毛:怎么能让猫自愿吃辣椒? 刘:掐着脖子灌. 毛:强迫不是自愿. 周: 先饿几天,再混到猫爱吃的东西里. 毛:欺骗不是自愿.把辣椒涂到猫肛门上,它就会自己去舔了. ...
- 【LeetCode】860. Lemonade Change 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode] Lemonade Change 买柠檬找零
At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and ...
- 如何一步一步用DDD设计一个电商网站(四)—— 把商品卖给用户
阅读目录 前言 怎么卖 领域服务的使用 回到现实 结语 一.前言 上篇中我们讲述了“把商品卖给用户”中的商品和用户的初步设计.现在把剩余的“卖”这个动作给做了.这里提醒一下,正常情况下,我们的每一步业 ...
- Java多线程卖票例子
package com.test; public class SaleTickets implements Runnable { private int ticketCount = 10;// 总的票 ...
- TopCoder kawigiEdit插件配置
kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...
- 1奶茶店创业成本: 2发饰品加盟店创业成本 3眼镜行业店创业成本 从“程序员转行卖烧饼”想到IT人创业
总结: -------奶茶店创业成本: 而这个奶茶店初期投资是:3万元加盟费+1万元保证金+8000装修+两万设备(冰柜.展示柜.收银机等等).别说赚钱,什么时候把初期投资赚回来呀! 一个店的利润就是 ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- TopCoder比赛总结表
TopCoder 250 500 ...
随机推荐
- Hibernate框架的使用。。。
在lib文件夹里面导入Hibernate开发的架包和连接mysql,连接数据源c3p0的架包... 在src目录下建立Hibernate Configuration File(cfg.xml)的配置 ...
- caffe ubuntu16安装报错和程序总结
我最近安装安装了老版本的caffe,安装过程真是两个字"想死",所以我的错误一般都是比较经典的. 我是使用cuda的版本,所以可能会出现undefined refference t ...
- Cheatsheet: 2016 01.01 ~ 01.31
Mobile An Introduction to Cordova: Basics Web Angular 2 versus React: There Will Be Blood How to Bec ...
- eclipse https git
open preferences via application menu Window => Preferences (or on OSX Eclipse => Settings). N ...
- CSS3之尖角标签
如图所示,Tag标签的制作通常使用背景图片,现在用CSS3代码就能实现尖角效果(需浏览器支持CSS3属性). 运用CSS3样式实现尖角标签,只需要写简单的HTML结构和CSS样式. <p> ...
- 程序设计入门——C语言 第1周编程练习 1逆序的三位数(5分)
第1周编程练习 查看帮助 返回 第1周编程练习题,直到课程结束之前随时可以来做.在自己的IDE或编辑器中完成作业后,将源代码的全部内容拷贝.粘贴到题目的代码区,就可以提交,然后可以查看在线编译和运 ...
- [原创] RT7 Lite win7旗舰版精简方案
[原创] RT7 Lite win7旗舰版精简方案 墨雪SEED 发表于 2016-1-26 21:23:54 https://www.itsk.com/thread-362912-1-5.html ...
- 【转】 TCP协议中的三次握手和四次挥手(图解)
建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看如何建立连接的. 首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资 ...
- ruby bundle config 镜像映射配置
新增映射 : bundle config mirror.https://rubygems.org/ http://ruby.taobao.com #所有对source https://rubygems ...
- ToolStrip添加自定义的DateTimePicker
直接新建一个类,代码如下: [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All), DefaultEven ...