CF1066B Heaters】的更多相关文章

题意描述: Vova先生的家可以看作一个n×1的矩形,寒冷的冬天来了,Vova先生想让他的家里变得暖和起来.现在我们给你Vova先生家的平面图,其中111表示这个地方是加热炉,0表示这个地方什么也没有.所有加热器都有一个加热半径r,一个位于ai加热器可以加热[ai−r+1,ai+r−1]的范围.现在,Vova先生想让他的整个家都变得暖和,一开始所有的加热器都是关闭的,请你求出Vova先生最少要开几个加热器才能使整个家变得暖和 输入输出格式: 输入格式: 第一行:两个整数n,r(1≤n,r≤100…
思路: 从左向右贪心选择能覆盖当前位置的最靠右的那个heater即可,和poj radar installation类似. 实现: #include <iostream> #include <cassert> using namespace std; const int INF = 0x3f3f3f3f; ], cov[]; int main() { int n, r; while (cin >> n >> r) { fill(cov + , cov + n…
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all…
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all…
https://leetcode.com/problems/heaters/ 开始的时候,下面的代码对于两边数字完全一样的情况,测试不通过.原因是heater会有重复情况,这时候对于飘红部分就不会往前面继续检查.所以把<改成<=让相同的情况也继续往前面走,走到最后一个,就可以了.Accepted! package com.company; import java.util.Arrays; class Solution { public int findRadius(int[] houses,…
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all…
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all…
这是悦乐书的第239次更新,第252篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第106题(顺位题号是475).冬天来了!您在比赛期间的第一份工作是设计一个固定温暖半径的标准加热器,以加热所有房屋.现在,您可以在水平线上获得房屋和加热器的位置,找出加热器的最小半径,以便所有房屋都能被这些加热器覆盖.因此,您的输入将分别是房屋和加热器的位置,您的预期输出将是加热器的最小半径.例如: 输入:[1,2,3],[2] 输出:1 说明:唯一的加热器在位置2,如果我们使用半径…
problem 475. Heaters solution1: class Solution { public: int findRadius(vector<int>& houses, vector<int>& heaters){ , cur = , j = ; sort(houses.begin(), houses.end()); sort(heaters.begin(), heaters.end()); ; i<houses.size(); i++) {…
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { public: int findRadius(vector<int>& houses, vector<int>& heaters) { sort(heaters.begin(),heaters.end()); ; int szHouses=houses.size(); ;i&l…