475 Heaters 加热器
详见:https://leetcode.com/problems/heaters/description/
C++:
class Solution {
public:
int findRadius(vector<int>& houses, vector<int>& heaters)
{
int n = heaters.size(), j = 0, res = 0;
sort(houses.begin(), houses.end());
sort(heaters.begin(), heaters.end());
for (int i = 0; i < houses.size(); ++i)
{
int cur = houses[i];
while (j < n - 1 && abs(heaters[j + 1] - cur) <= abs(heaters[j] - cur))
{
++j;
}
res = max(res, abs(heaters[j] - cur));
}
return res;
}
};
参考:http://www.cnblogs.com/grandyang/p/6181626.html
475 Heaters 加热器的更多相关文章
- 【leetcode】475. Heaters
problem 475. Heaters solution1: class Solution { public: int findRadius(vector<int>& house ...
- 【LeetCode】475. Heaters 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...
- [LeetCode] Heaters 加热器
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- [Leetcode] Binary search -- 475. Heaters
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- 475. Heaters
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 475. Heaters (start binary search, appplication for binary search)
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- 475. Heaters 加热范围
[抄题]: Winter is coming! Your first job during the contest is to design a standard heater with fixed ...
- LeetCode_475. Heaters
475. Heaters Easy Winter is coming! Your first job during the contest is to design a standard heater ...
- 【LeetCode】二分
[475] Heaters [Easy] 给你一排房子,一排加热器.找到能warm所有房子的最小加热器半径. 思路就是对于每个房子,找离它最近的左右两台heater, 分别求距离.温暖这个房子的hea ...
随机推荐
- Writing a Discard Server
Netty.docs: User guide for 4.x https://netty.io/wiki/user-guide-for-4.x.html
- JSON和JavaScript对象
var obj={width:100,height:200},这样的并不叫JSON,并且JSON只是一种数据格式,并不是具体的实例. 但很多人把这样的JS对象当成JSON,下面把这个问题讲清楚 一.J ...
- 20170225 ABAP获取字符串长度/字节长度
函数YGET_CHAR_LONG: FUNCTION YGET_CHAR_LONG. *"-------------------------------------------------- ...
- ios实现倒计时的两种方法
方法1:使用NSTimer来实现 主要使用的是NSTimer的scheduledTimerWithTimeInterval方法来每1秒执行一次timeFireMethod函数,timeFireMeth ...
- Fastreport生成WEB报表
开发WEB应用系统通常都会遇到报表打印问题.简单应用可利用IE的页面打印功能,利用HTML标签控制格式来实现.但复杂的业务型应用系统,报表不仅是组成应用的 重要部分,还常常是相当复杂的.现在很多应用系 ...
- bzoj3090: Coci2009 [podjela]
这个范围明显树包的 然而值并不滋磁 想了一会发现可以带一维当前子树用了多少边,搞定当前向上还能送多少 然后发现会有搞不定的情况,要向上传负数 每次都要重新初始化,负数强制要要 #include< ...
- asp.net下的cookieName
https://stackoverflow.com/questions/1017144/rename-asp-net-sessionid Add to your web.config:- <sy ...
- BZOJ_2726_[SDOI2012]任务安排_斜率优化+二分
BZOJ_2726_[SDOI2012]任务安排_斜率优化+二分 Description 机器上有N个需要处理的任务,它们构成了一个序列.这些任务被标号为1到N,因此序列的排列为1,2,3...N.这 ...
- 【213】IDL函数汇总
名称 功能说明 类型 语法&举例 IDL_VALIDNAME 判断变量名是否有效,无效返回值为空或者自动修改 函数 DEFSYSV 自定义系统变量,全局变量 过程 MAKE_ARRA ...
- 【210】通过OleDb读写Excel数据到DataTable
参考:C#通过OLEDB读写Excel2013显示到datagrid控件,修改数据集并更新excel2013 解决:未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序.( ...