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. QQ空间点赞代码

    jQuery("a.qz_like_btn_v3[data-clicklog='like']").each(function(index,item){ console.log(it ...

  2. java 面向对象 — 类和对象

    构造方法 1.构造器必须与类同名(如果一个源文件中有多个类,那么构造器必须与公共类同名) 2.每个类可以有一个以上的构造器 3.构造器可以有0个.1个或1个以上的参数 4.构造器没有返回值 5.构造器 ...

  3. 原生态JDBC问题的总结

    package com.js.ai.modules.aiyq.testf; import java.sql.Connection; import java.sql.DriverManager; imp ...

  4. JSP自定义业务标签

    自定义标签: package cn.hv.tag; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; ...

  5. 操作表单域中的value值

    HTML <form action=""> <input type="radio" name="sex" value=&q ...

  6. OpenCL 直方图

    ▶ 计算直方图,由原子计数和规约计算两部分组成 ● 最简单的版本,代码 // kernel.cl #pragma OPENCL EXTENSION cl_khr_local_int32_base_at ...

  7. 跟我学算法- tensorflow VGG模型进行测试

    我们使用的VGG模型是别人已经训练好的一个19层的参数所做的一个模型 第一步:定义卷积分部操作函数 mport scipy.io import numpy as np import os import ...

  8. 开关 toggleClass('hide')

    toggleClass 实现属性的反转 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  9. How to run eclipse in clean mode? and what happens if we do so?

    What it does: if set to "true", any cached data used by the OSGi framework and eclipse run ...

  10. JDK8新特性:函数式接口@FunctionalInterface的使用说明

    我们常用的一些接口Callable.Runnable.Comparator等在JDK8中都添加了@FunctionalInterface注解. 通过JDK8源码javadoc,可以知道这个注解有以下特 ...