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 ...
随机推荐
- javascript常用事件及方法
1.获取鼠标坐标,考虑滚动条拖动 var e = event || window.event; var scrollX = document.documentElement.scrollLeft || ...
- redis12-----redis 与关系型数据库的对比
书和书签系统 create table book ( bookid int, title ) )engine myisam charset utf8; insert into book values ...
- 从源码理解 ThreadLocal
为每个线程保存各自的拷贝,可以通过在Thread类中定义一个成员变量来保存每个线程值,这样也是线程安全的. 通过定义一个成员变量 sn 来实现,这里并没有使用ThreadLocal类来实现: publ ...
- 利用Python3的dpkt库进行ARP扫描
背景 正在学习网络协议,用Python写起来方便点,可以快速熟悉协议本身,也给自己补充一些Python库. 偶然看到这篇文章,讲的是Python发ARP包,发现是Python2的,这里改了一下,用Py ...
- POJ3984 迷宫问题 —— BFS
题目链接:http://poj.org/problem?id=3984 迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- [原创]java合并word文件
需求背景 在互联网教育行业,做内容相关的项目经常碰到的一个问题就是如何动态生成一张word试卷.事先把题库中的每一道试题都已经保存成一个独立的word文件了,但是在选择了部分试题生成一张word试卷的 ...
- ubuntu中使用apt-get安装zbar
apt-get是linux中常用的shell命令,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索.安装.升级.卸载软件或操作系统.apt-get命令一般需要root权限执行,所以 ...
- [Selenium] Selenium find Element Examples
---> 1. By.id 以百度主页为例 <span classs = "bg s_ipt_wr"> <input type = "text& ...
- wsdl 生成代码 WCF
具体方法: 打开Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 命令提示窗口. 输入:wsdl ...
- HTTP 请求的组成 方法 已经 请求的状态码
HTTP请求是指从客户端到服务器端的请求消息. 包括:消息首行中,对资源的请求方法.资源的标识符及使用的协议.从客户端到服务器端的请求消息包括,消息首行中,对资源的请求方法.资源的标识符及使用的协议. ...