static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int findRadius(vector<int>& houses, vector<int>& heaters)
{
sort(heaters.begin(),heaters.end());
int minRadius=;
int szHouses=houses.size();
for(int i=;i<szHouses;i++)
{
int curRadius=INT_MAX;
auto larger=lower_bound(heaters.begin(),heaters.end(),houses[i]);
if(larger!=heaters.end())
curRadius=*larger-houses[i];
if(larger!=heaters.begin())
{
auto smaller=larger-;
curRadius=min(curRadius,houses[i]-*smaller);
}
minRadius=max(minRadius,curRadius);
}
return minRadius;
}
};

找最小热源半径,扫描房屋数组,找到所有房屋被最近热源覆盖所需要的热源半径,取这些所有半径的最大值即可。

值得注意的是两头的情况和中间额情况不同,一个房屋两侧都有热源时,要取两边覆盖半径的较小值。

475. Heaters的更多相关文章

  1. 【leetcode】475. Heaters

    problem 475. Heaters solution1: class Solution { public: int findRadius(vector<int>& house ...

  2. [Leetcode] Binary search -- 475. Heaters

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  3. 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 ...

  4. 475. Heaters 加热范围

    [抄题]: Winter is coming! Your first job during the contest is to design a standard heater with fixed ...

  5. 475 Heaters 加热器

    详见:https://leetcode.com/problems/heaters/description/ C++: class Solution { public: int findRadius(v ...

  6. 【LeetCode】475. Heaters 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...

  7. LeetCode_475. Heaters

    475. Heaters Easy Winter is coming! Your first job during the contest is to design a standard heater ...

  8. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

  9. leetcode bugfree note

    463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...

随机推荐

  1. cratedb geo 查询

    cratedb支持的geo 查询还相对比较全,开发基本的功能已经够用了 安装cratedb 使用docker docker run -d -p 4200:4200 crate 创建数据库 创建表 CR ...

  2. 使用xUnit为.net core程序进行单元测试(2)

    第一部分: http://www.cnblogs.com/cgzl/p/8283610.html 下面有一点点内容是重叠的.... String Assert 测试string是否相等: [Fact] ...

  3. Web验证方式(1)--Http Basic Authentication

    Http Basic Authentication是HTTP协议中定义的Web系统中的验证方式.参考wiki 主要的实现机制如下: 1. 用户通过浏览器匿名访问web资源. 2. web服务器检测到w ...

  4. ivy antlib shemalocation

    <?xml version="1.0" encoding="UTF-8"?> <project name="yourproject& ...

  5. Java反射机制的适用场景及其利与弊 ***

    一.反射的适用场景是什么? 1).Java的反射机制在做基础框架的时候非常有用,有一句话这么说来着:反射机制是很多Java框架的基石.而一般应用层面很少用,不过这种东西,现在很多开源框架基本都已经给你 ...

  6. 黄聪:利用iframe实现ajax 跨域通信的解决方案(转)

    原文:http://www.cnblogs.com/xueming/archive/2013/02/01/crossdomainajax.html 在漫长的前端开发旅途上,无可避免的会接触到ajax, ...

  7. java web 程序---购物车项目内容:

    1.项目介绍   典型电子商务系统(在线购物平台).模拟了当当系统部分功能.2.功能需求    1)用户管理模块(3天)user         实现登录.注册功能    2)产品浏览模块(2天)ma ...

  8. git 回退到制定commit

    git clone XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX git log -5 // 查看最近5个commit 回退命令:$ git reset --hard HEAD^ ...

  9. 第 0 课 Golang环境搭建

    1  下载 https://studygolang.com/dl  2   安装完成后,查看环境变量 GOBIN 存放可执行文件的目录的绝对路径. GOPATH 工作区目录的绝对路径.存放远源码的路径 ...

  10. 转 linux 下装 usb driver

    http://www.george-smart.co.uk/wiki/Xilinx_JTAG_Linux