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. BZOJ1233 [Usaco2009Open]干草堆tower 和 BZOJ3549 [ONTAK2010]Tower

    题意 Problem 3549. -- [ONTAK2010]Tower 3549: [ONTAK2010]Tower Time Limit: 10 Sec  Memory Limit: 64 MBS ...

  2. kudu yum 安装

    yum 源 http://archive.cloudera.com/kudu/redhat/7/x86_64/kudu/cloudera-kudu.repo [cloudera-kudu] # Pac ...

  3. HR-人力资源管理系统(Human Resources Management System,HRMS)

    人力资源管理系统(Human Resources Management System,HRMS),是指组织或社会团体运用系统学理论方法,对企业的人力资源管理方方面面进行分析.规划.实施.调整,提高企业 ...

  4. 利用WeX5给手机APP增加短信验证码功能

    帖子来源:http://bbs.wex5.com/thread-70908-1-1.html 遇到一个手机APP项目客户要求注册到APP上的用户手机号必须是真实的通过X5平台整合短信发送平台接口完成了 ...

  5. android studio安装须知

    64位linux,默认会提示mksdcard错误什么的,需要安装一个库 sudo apt- android sdk的下载,自己找代理服务器吧,哎……

  6. Java-Runoob-高级教程-实例-字符串:03. Java 实例 - 删除字符串中的一个字符

    ylbtech-Java-Runoob-高级教程-实例-字符串:03. Java 实例 - 删除字符串中的一个字符 1.返回顶部 1. Java 实例 - 删除字符串中的一个字符  Java 实例 以 ...

  7. [原][Java]eclipse 修改自动提示

    下载 jar 链接:http://files.cnblogs.com/files/z5337/org.eclipse.jface.text_3.7.2.v20111213-1208.zip 或者这个: ...

  8. 本地通过源码方式启动solr

      首先,下载solr5.5.0源码,http://apache.fayea.com/lucene/solr/5.5.0/solr-5.5.0-src.tgz   解压完成后,分为几个目录,然而sol ...

  9. JSP的taglib示例

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2 ...

  10. <转>cocos2d-x学习笔记(五)仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)

    转载自ufolr的博客 原文连接:http://blog.csdn.net/ufolr/article/details/7624851 最近项目中需要一个落叶的效果,本来想用粒子特效来实现,但是几经调 ...