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 ...
随机推荐
- java sleep和wait的区别和联系
Thread.sleep不会改变锁的行为,如果当前线程拥有锁,那么当前线程sleep之后,该锁不会被释放. Thread.sleep和Object.wait都会暂停当前的线程,让出cpu.Thread ...
- JOptionPane常用提示框
//JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon); JOptionPane.sho ...
- 大整数分解质因数(Pollard rho算法)
#include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> ...
- [Android6.0][RK3399] 修改默认按键 KEY-PAD 的功能【转】
本文转载自:http://m.blog.csdn.net/dearsq/article/details/70175637 Platform: RK3399 OS: Android 6.0 Kernel ...
- HDU3045 Picnic Cows —— 斜率优化DP
题目链接:https://vjudge.net/problem/HDU-3045 Picnic Cows Time Limit: 8000/4000 MS (Java/Others) Memor ...
- 设置linux服务器下开放端口
查询 netstat -anp 所有开放端口信息 二.关闭端口号: iptables -A OUTPUT -p tcp --dport 端口号-j DROP 三.打开端口号: iptables -A ...
- 如何在cowboy应用中指定mnesia数据库路径
创建mnesia数据库的步骤简述: 1)定义脚本: -module(mns). -export([setup/0, clean/0]). -record(user, { id, coin, diamo ...
- MYSQL数据库学习----查询
查询语句是MYSQL数据库中用到的最多的语句. 查询语句分为几种 单表查询 集合函数查询 连接查询 子查询 合并查询 正则表达式查询 一:单表查询 SELECT 属性 FROM 表名 [WHERE 查 ...
- Spring 3.1新特性之一:使用Spring Profile和Mybatis进行多个数据源(H2和Mysql)的切换
最近在做WebMagic的后台,遇到一个问题:后台用到了数据库,本来理想情况下是用Mysql,但是为了做到开箱即用,也整合了一个嵌入式 数据库H2.这里面就有个问题了,如何用一套代码,提供对Mysql ...
- bootstrap-Glyphicons 字体图标
使用的方法: 1 引入 font-awesome.css文件 2 fonts文件夹 Bootstrap 假定所有的图标字体文件全部位于 ../fonts/ 目录内(可以在font-awesome.c ...