475. Heaters
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的更多相关文章
- 【leetcode】475. Heaters
problem 475. Heaters solution1: class Solution { public: int findRadius(vector<int>& house ...
- [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 (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 ...
- 475 Heaters 加热器
详见:https://leetcode.com/problems/heaters/description/ C++: class Solution { public: int findRadius(v ...
- 【LeetCode】475. Heaters 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...
- LeetCode_475. Heaters
475. Heaters Easy Winter is coming! Your first job during the contest is to design a standard heater ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- leetcode bugfree note
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...
随机推荐
- 生成.eps文件方法
生成.eps文件方法 背景: 要写论文了,图像的分辨率是一大痛点 方法一: 两步生成.eps文件 用visio 制作图形,保存为pdf格式: 直接用adobe acrobat 打开pdf,然后保存为. ...
- memcache 命令行操作
今天找了很久,如何在服务器直接查看memcache 的值, 来确定php中memcache是否已经写进去了 https://www.ttlsa.com/memcache/memcache-list-a ...
- 黄聪:VPS配置Filezilla Server支持FTP的Passive被动模式(FTP连接不上怎么办?有详细教程)
Filezilla Server的配置: 1.Filezilla默认的模式是Port模式,不是Passive被动模式.为了解决防火墙后的客户端连接问题,最好是启用Passive模式.要启动被动模式,首 ...
- java课程设计-坦克大战
团队课程设计博客链接 个人负责模块 枚举类.工具类.子弹类.图片素材的查找,地图制作 Git管理 包名类名的命名 详细说明 枚举类 如 单人和双人模式 工具类 将每个图片的路径使用字符串保存,便于调用 ...
- Python格式化输出%s和%d
python print格式化输出. 1. 打印字符串 print ("His name is %s"%("Aviad")) 效果: 2.打印整数 print ...
- 分类预测输出precision,recall,accuracy,auc和tp,tn,fp,fn矩阵
此次我做的实验是二分类问题,输出precision,recall,accuracy,auc # -*- coding: utf-8 -*- #from sklearn.neighbors import ...
- [转]Web前端浏览器兼容
转自: http://www.admin10000.com/document/1900.html 前言 浏览器兼容是前端开发人员必须掌握的一个技能,但是初入前端的同学或者其他后台web开发同学往往容易 ...
- 移动自动化测试:Android Studio 、Appium、夜神模拟器
环境是Window 10 64位 第一章:安装Appium Appium和node.js需要一起安装,他们的依赖关系暂不深究. 1. node.js傻瓜式安装 官网地址:https://nodejs. ...
- mybatis“$”和“#”
摘要:$ 是直接拼接# 会转义,更安全 类比Mybatis的执行流程和JDBC原有的我们使用的方法就是:Mybatis: Sqlsession -> Executor -> Stateme ...
- Spring IO Platform介绍
为什么要用Spring IO Platform 今天无意间看到了一个关键词:"Spring IO Platform",第一直觉是不是有关于IO方面的框架或者包呢,查了一下,居然是为 ...