leetcode_1052. Grumpy Bookstore Owner
1052. Grumpy Bookstore Owner
https://leetcode.com/problems/grumpy-bookstore-owner/
题意:每个时刻i会有customer[i]个顾客进店,在i时刻店主的情绪是grumpy[i],若grumpy[i]==1则店主脾气暴躁,那么顾客会不满意,否则顾客讲感到满意,店主会一个技巧保证连续X时间内不暴躁,但他只能使用一次。问最多可以有多少顾客满意。
解法:找到一个连续X时间段,使用技巧后,得到的收益最大。计算前缀和,然后依次遍历所有连续X时间段,找到使用技巧能使最多的顾客从不满意变为满意。
class Solution
{
public:
int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int X)
{
vector<int> presum(grumpy.size());
if(grumpy[]==)
presum[]=customers[];
for(int i=;i<grumpy.size();i++)
{
presum[i]=grumpy[i]==?(presum[i-]+customers[i]):presum[i-];
}
int max_sum=presum[X-],last_pos=X-;
for(int i=X;i<grumpy.size();i++)
{
int st_pos = i-X+;
if(max_sum<presum[i]-presum[st_pos-])
{
max_sum=presum[i]-presum[st_pos-];
last_pos=i;
}
}
int res=;
for(int i=;i<grumpy.size();i++)
{
if(grumpy[i]==)
res+=customers[i];
else if(i>=last_pos-X+&&i<=last_pos)
res+=customers[i];
}
return res;
}
};
leetcode_1052. Grumpy Bookstore Owner的更多相关文章
- 【leetcode】1052. Grumpy Bookstore Owner
题目如下: Today, the bookstore owner has a store open for customers.length minutes. Every minute, some ...
- Weekly Contest 138
1051. Height Checker Students are asked to stand in non-decreasing order of heights for an annual ph ...
- 100-days: twenty-eight
Title: Lawrence Ferlinghetti's(劳伦斯·费林盖蒂) enduring San Francisco(旧金山) 劳伦斯·费林盖蒂心中的旧金山,历久弥新 费林盖蒂:美国垮掉的一 ...
- owner:轻松管理java项目配置
前段时间,一同事说在 github 上“活捉了”一个很有趣的开源项目,它是一个超轻量级的 jar 包,能够帮助你在 java 项目中摒弃样板式的 properties 配置代码,让你轻松自如地管理和使 ...
- IOS 杂笔-14(被人遗忘的owner)
*owner在开发中现在已经很少用了 有兴趣的童鞋可以看看* 我们遇到owner通常是在类似 [[[NSBundle mainBundle] loadNibNamed:@"Food" ...
- 【转】WPF: 自动设置Owner的ShowDialog 适用于MVVM
原文地址:http://www.mgenware.com/blog/?p=339 WPF中的Windows的ShowDialog方法并没有提供设置Owner的参数,开发者需要在ShowDialog前设 ...
- Linked Server: EXECUTE permission denied on object 'xp_prop_oledb_provider', database 'master', owner 'dbo'
问题出现环境: 使用SQL Server Management Studio 2008 连接到SQL Server 2000的数据库,点击其中一个Oracle链接服务器,单击"目录" ...
- Unable to determine if the owner (Domain\UserName) of job JOB_NAME has server access
早上巡检的的时候,发现一数据库的作业报如下错误(作业名等敏感信息已经替换),该作业的OWNER为一个域账号: JOB RUN: 'JOB_NAME' was run on 2016-6-1 at 7: ...
- SQL Server修改数据库对象所有者(Owner)浅析
在SQL Server数据库中如何修改数据库对象(表.视图.存储过程..)的所有者(Owner)呢?一般我们可以使用系统提供的系统存储过程sp_changeobjectowner来修改. 我们先看看s ...
随机推荐
- httpclient:实现有验证码的模拟登陆
//1.这种方式是先把验证码的图片下载到本地.并且根据网页解析获得token值//2.手动在控制台输入验证码//3.因为验证码图片已经下载下来,后面就可以使用图像文字识别package DoubanS ...
- java集合框架之比较器Comparator、Comparable
参考http://how2j.cn/k/collection/collection-comparator-comparable/693.html Comparator 假设Hero有三个属性 name ...
- 4-1数据类型转换的基本概念 & 4-2 & 4-3数据类型转换案例 & 4-4习题
4-1数据类型转换的基本概念 253是int类型的,赋值给长整型的n 这种就是强制的类型转换 自动类型转换又叫做饮食类型转换,因为他的转换我们是看不到的 实线表示无数据丢失的 虚线在转换时, doub ...
- vi/vim打开文件提示Found a swap file by the name
问题分析 有一次在远程连接主机时,用vi打开文件my.ini却提示:Found a swap file by the name ".my.ini.swp".百度了下才知道,原来在使 ...
- python_argparse
使用python argparser处理命令行参数 #coding:utf-8 # 导入模块 import argparse # 创建ArgumentParser()对象 parser = argpa ...
- 获取元素属性 和 获取元素的CSS属性
- 应用性能监控-web系统
1 系统规划 参考https://mp.weixin.qq.com/s/UlnHOaN0xaA0jfg5CEmLRA 1.1 数据采集的原则: 数据采集,说起来比较简单,只要把数据报上来就行,具体怎么 ...
- bzoj3583 杰杰的女性朋友 || bzoj4362 Graph
http://210.33.19.103/problem/2174 很显然是矩阵快速幂的题,设有in和ou矩阵,设in矩阵的转置为in' 显然可以直接暴力求出任意两点间走一步路径条数,然后求其d次幂, ...
- IDEA Maven无法添加依赖到项目中
IDEA--------->File-------->Setting------------>Maven 勾上即可,OK啦! 完美解决了
- hdu4419Colourful Rectangle
链接 分别求出7种颜色覆盖的面积. 做法:每种颜色设定一个标号,以二进制表示R:100 G:010 B:001 .这样很明显可以知道RG:110 GB:011 以此类推. 求解时,需要开一个二维标记数 ...