517 Super Washing Machines 超级洗衣机
详见:https://leetcode.com/problems/super-washing-machines/description/
C++:
class Solution {
public:
int findMinMoves(vector<int>& machines)
{
int sum = accumulate(machines.begin(), machines.end(), 0);
if (sum % machines.size() != 0)
{
return -1;
}
int res = 0, cnt = 0, avg = sum / machines.size();
for (int m : machines)
{
cnt += m - avg;
res = max(res, max(abs(cnt), m - avg));
}
return res;
}
};
参考:http://www.cnblogs.com/grandyang/p/6648557.html
517 Super Washing Machines 超级洗衣机的更多相关文章
- [LeetCode] Super Washing Machines 超级洗衣机
You have n super washing machines on a line. Initially, each washing machine has some dresses or is ...
- Leetcode - 517 Super Washing Machines
今天开始定期记录本人在leetcode上刷题时遇到的有意思的题目. 517. Super Washing Machines You have n super washing machines ...
- 517. Super Washing Machines
▶ 超级洗碗机.给定一个有 n 元素的整数数组,我们把 “将指定位置上元素的值减 1,同时其左侧或者右侧相邻元素的值加 1” 称为一次操作,每个回合内,可以选定任意 1 至 n 个位置进行独立的操作, ...
- 第十五周 Leetcode 517. Super Washing Machines(HARD) 贪心
Leetcode517 很有趣的一道题 由于每一步可以任选某些数字对它们进行转移,所以实际上是在求最优解中的最复杂转移数. 那么我们考虑,到底哪一个位置要经过的流量最大呢? 枚举每个位置,考虑它左边的 ...
- [Swift]LeetCode517. 超级洗衣机 | Super Washing Machines
You have n super washing machines on a line. Initially, each washing machine has some dresses or is ...
- LeetCode517. Super Washing Machines
You have n super washing machines on a line. Initially, each washing machine has some dresses or is ...
- Java实现 LeetCode 517 超级洗衣机
517. 超级洗衣机 假设有 n 台超级洗衣机放在同一排上.开始的时候,每台洗衣机内可能有一定量的衣服,也可能是空的. 在每一步操作中,你可以选择任意 m (1 ≤ m ≤ n) 台洗衣机,与此同时将 ...
- Leetcode 517.超级洗衣机
超级洗衣机 假设有 n 台超级洗衣机放在同一排上.开始的时候,每台洗衣机内可能有一定量的衣服,也可能是空的. 在每一步操作中,你可以选择任意 m (1 ≤ m ≤ n) 台洗衣机,与此同时将每台洗衣机 ...
- [LeetCode] Super Ugly Number 超级丑陋数
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...
随机推荐
- jvm 调优(2)垃圾回收算法
可以从不同的的角度去划分垃圾回收算法: 按照基本回收策略分 引用计数(Reference Counting): 比较古老的回收算法.原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数. ...
- all rows from client_id can grow infinitely compared to a single node when hashing by client_id
all rows from client_id can grow infinitely compared to a single node when hashing by client_id Re: ...
- SignatureDoesNotMatch REST接口 在任何时间、任何地点、任何互联网设备上 在Header中包含签名
PutObject_关于Object操作_API 参考_对象存储 OSS-阿里云 https://help.aliyun.com/document_detail/31978.html OSS API ...
- hdfs namenode出错
http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_design.html 健壮性 HDFS的主要目标就是即使在出错的情况下也要保证数据存储的可靠性.常见的三种出 ...
- nginx搭建支持http和rtmp协议的流媒体server之中的一个
实验目的:让Nginx支持flv和mp4格式文件,支持RTMP协议的直播和点播:同一时候打开RTMP的HLS功能 资料:HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的 ...
- RestClient写法
response = RestClient::Request.execute(:method=>:post, :url=> “http×××××”, :payload=>{:id=& ...
- 软件GUI测试中的关注点
[摘要] 本文列数了软件黑盒测试过程中,在被测试软件中可能存在的常见软件问题.本文不会详细讨论基本的软件测试思想与常用技术,仅针对在软件黑盒测试过程中若干的问题做描述,并提供个人的参考测试意见与防范意 ...
- 编程方式取得Spring上下文的Properties
在spring初始化时,可以使用Properties配置器把properties文件装载到Spring的上下文中. ... xmlns:context="http://www.springf ...
- I.MX6 2G DDR3 16G eMMC
/************************************************************************* * I.MX6 2G DDR3 16G eMMC ...
- (转)Vim自动补全神器:YouCompleteMe
原文出处:http://blog.jobbole.com/58978/ 第一次听说这个插件还是在偶然的情况下看到别人的博客,听说了这个插件的大名.本来打算在实训期间来完成安装的,无奈网实在不给力,也就 ...