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 ...
随机推荐
- axis、xfire、CXF 、JWS
1.JWS是Java语言对WebService服务的一种实现,用来开发和发布服务.而从服务本身的角度来看JWS服务是没有语言界限的.但是Java语言为Java开发者提供便捷发布和调用WebServic ...
- spring中PropertyPlaceholderHelper替换占位符的值
1.Properties中的值替换¥{}或者#{}占位符 String text = "foo=${foo},bar=${bar}"; Properties props = new ...
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
01 Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- JavaScript SHA-1
1. [文件] webtoolkit.sha1.js ~ 4KB /**** Secure Hash Algorithm (SHA1)* http://www.huiyi8.com/css ...
- Maze 解题报告
Maze Description You are given a special Maze described as an n*m matrix, please find the shortest ...
- ${varname:-defaultvalue}
${varname:-defaultvalue}的意思是:如果varname存在且非null,则返回其值:否则,返回defaultvalue. 用途:如果变量未定义,则返回默认值.
- I.MX6 Android 5.1.1 下载、编译
/************************************************************************* * I.MX6 Android 5.1.1 下载. ...
- 酷版移动端iframe改变src,重新加载页面问题探究
最近在酷版上我要做一个内嵌别人的网页的在线服务页面,于是必须用到iframe,以前我以为移动端不支持iframe呢,原来这样都可以....(呵呵,长见识了!我还是只菜鸟) 直接入正题,说说我遇到的困难 ...
- node fs模块
Node.js的文件系统的Api //公共引用 var fs = require('fs'), path = require('path'); 1.读取文件readFile函数 //readFile( ...
- python的time模块使用
在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: ...