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总的的边数减去重叠的 ...
随机推荐
- 使用 Content-Encoding: br 替换 Content-Encoding: gzip
今天在测试一个web 框架的时候无意发现框架运行是响应头时有一个 Content-Encoding: br 发现是一个gzip 算法的替代,同时压缩比很不错 浏览器兼容性如下: nginx 的配置参考 ...
- Linux和Docker常用命令
一.常用Linux 命令 ls -a(同时列出隐含文件), -l(输出一个比较完整的格式,除每个文件名外,增加显示文件 类型.权限.硬链接数.所有者名.组名.大小(byte).及时间信息-----简化 ...
- POJ3070 矩阵快速幂模板
题目:http://poj.org/problem?id=3070 矩阵快速幂模板.mod写到乘法的定义部分就行了. 别忘了 I ( ) 和 i n i t ( ) 要传引用! #include< ...
- Linux内核 TCP/IP参数调优
http://www.360doc.com/content/14/0606/16/3300331_384326124.shtml
- laravel 数据库操作
1 配置信息 1.1配置目录: config/database.php 1.2配置多个数据库 //默认的数据库 'mysql' => [ 'driver' => 'mysql', 'hos ...
- 智能家居入门DIY——【五、执行命令】
前面几篇介绍了ESP8266使用AT命令来连接WIFI实现一系列功能.这一篇介绍一下使用Wemos D1 Wifi来进行开发,当然也可以用常见的8针ESP8266来完成(只是需要按网上的方法将Ardu ...
- try catch finally ,try 中有return时怎么执行
- (转)2009-05-25 22:12 Outlook2007选择发送帐号
本文转载自:http://hi.baidu.com/vugwggogodaenqe/item/c95c6d019457a2d873e676ec outlook2007可以用程序选择发送帐号,其他的版本 ...
- 管理Linux服务器的用户和组
管理Linux服务器的用户和组 Linux操作系统是一个多用户多任务的操作系统,允许多个用户同时登录到系统,使用系统资源. 为了使所有用户的工作顺利进行,保护每个用户的文件和进程,规范每个用户的权限, ...
- easyui制作进度条案例demo
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...