这是六则或许对你有些许帮助的信息:

1、阿秀在工作之余开发了一个编程资源网站,目前已经收集了很多不错的学习资源和黑科技(附带下载地址),如你有意欢迎体验以及推荐自己认为不错的资源,众人拾柴火焰高,我为人人,人人为我🔥!

2、👉23年5月份我从字节跳动离职跳槽到某外企期间,为方便自己找工作,增加上岸几率,我自己从0开发了一个互联网中大厂面试真题解析网站,包括两个前端和一个后端。能够定向查看某些公司的某些岗位面试真题,比如我想查一下行业为互联网,公司为字节跳动,考察岗位为后端,考察时间为最近一年之类的面试题有哪些?

网站地址:InterviewGuide大厂面试真题解析网站。点此可以查看该网站的视频介绍:B站视频讲解 如果可以的话求个B站三连,感谢!

3、😊 分享一个学弟发给我的20T网盘资源合集点此白嫖,主要是各类高清影视、电视剧、音乐、副业、纪录片、英语四六级考试、考研考公等资源。

4、😍免费分享阿秀个人学习计算机以来收集到的免费学习资源,点此白嫖;也记录一下自己以前买过的不错的计算机书籍、网络专栏和垃圾付费专栏;也记录一下自己以前买过的不错的计算机书籍、网络专栏和垃圾付费专栏

5、🚀如果你想在校招中顺利拿到更好的offer,阿秀建议你多看看前人踩过的坑留下的经验,事实上你现在遇到的大多数问题你的学长学姐师兄师姐基本都已经遇到过了。

6、🔥 欢迎准备计算机校招的小伙伴加入我的学习圈子,一个人踽踽独行不如一群人报团取暖,圈子里沉淀了很多过去21/22/23届学长学姐的经验和总结,好好跟着走下去的,最后基本都可以拿到不错的offer!此外,每周都会进行精华总结和分享!如果你需要《阿秀的学习笔记》网站中📚︎校招八股文相关知识点的PDF版本的话,可以点此下载

# 475. 供暖器,很经典

力扣原题链接(点我直达) (opens new window)

冬季已经来临。 你的任务是设计一个有固定加热半径的供暖器向所有房屋供暖。

现在,给出位于一条水平线上的房屋和供暖器的位置,找到可以覆盖所有房屋的最小加热半径。

所以,你的输入将会是房屋和供暖器的位置。你将输出供暖器的最小加热半径。

说明:

给出的房屋和供暖器的数目是非负数且不会超过 25000。 给出的房屋和供暖器的位置均是非负数且不会超过10^9。 只要房屋位于供暖器的半径内(包括在边缘上),它就可以得到供暖。 所有供暖器都遵循你的半径标准,加热的半径也一样。 示例 1:

输入: [1,2,3],[2] 输出: 1 解释: 仅在位置2上有一个供暖器。如果我们将加热半径设为1,那么所有房屋就都能得到供暖。 示例 2:

输入: [1,2,3,4],[1,4] 输出: 1 解释: 在位置1, 4上有两个供暖器。我们需要将加热半径设为1,这样所有房屋就都能得到供暖。

# 第一种,错误的

int minRadius(vector<int>& houses, int& pos1, int &pos2) {
	vector<int>::iterator it1 = find(houses.begin(), houses.end(), pos1);
	vector<int>::iterator it2 = find(houses.begin(), houses.end(), pos2);
	int radius1 = *(it1 + (it2 - it1) / 2) - pos1,radius2=pos2- *(it1 + (it2 - it1) / 2);
	
	//cout << " pos1 pos2  " << pos1 << "  " << pos2 << "   radius1  radius2 " << radius1 <<"  "<< radius2 << endl;
	return radius1>radius2?radius1:radius2;
}



int findRadius(vector<int>& houses, vector<int>& heaters) {
	if (heaters.size() == 1) return fabs(houses[0] - heaters[0]) > fabs(houses[houses.size() - 1] - heaters[0]) ? fabs(houses[0] - heaters[0]) : fabs(houses[houses.size() - 1] - heaters[0]);
	sort(houses.begin(), houses.end());
	sort(heaters.begin(), heaters.end());
	int maxRaius = 0;
	int temp = fabs(houses[0] - heaters[0]);
	maxRaius = maxRaius > temp ? maxRaius : temp;
	//cout << maxRaius << endl;
	for (vector<int>::iterator it = heaters.begin(); it != heaters.end()-1;++it ) {
		
		temp=minRadius(houses, *it, *(it+1));
		maxRaius = maxRaius > temp ? maxRaius : temp;
		//cout << maxRaius << endl;
	}
	temp = fabs(houses[houses.size() - 1] - heaters[heaters.size()-1]);
	maxRaius = maxRaius > temp ? maxRaius : temp;
	//cout << maxRaius << endl;
	return maxRaius;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

我的想法是,比较每两个热水器中间地方,距离房子的两边距离分别为多少。当然了,热水器为1的时候,就看第一个房子和最后一个房子到热暑期的距离,谁比较大了。比如[1,2,3,4],[1,4],其实最短距离为1,而不是2。

# 第二种,直接比较每个房屋前后热水器的距离

房屋左右侧的热水器,取距离小的那个,最终取的是所有房屋所需最大的那个半径。

int minRadius(vector<int>& heaters, int& target) {
	if (target < heaters[0]) return heaters[0] - target;
	if (target > heaters[heaters.size() - 1]) return target - heaters[heaters.size() - 1];
	int mid = 0, low = 0, high = heaters.size() - 1;
	while (low + 1 < high)
	{
		mid = low + (high - low) / 2;
		if (target == heaters[mid]) return 0;
		else if (target > heaters[mid]) {
			low = mid;
		}
		else {
			high = mid;
		}
	}//差值为1的时候就停止判断,所以需要再进行判断一下

	if (heaters[low] == target || heaters[high] == target) return 0;
	else
	{	return min(fabs(target - heaters[low]), fabs(target - heaters[high]));
	}
}



int findRadius(vector<int>& houses, vector<int>& heaters) {
	if (heaters.size() == 1) return max(heaters[0] - houses[0], houses[houses.size() - 1] - heaters[0]);
	sort(heaters.begin(), heaters.end());//对热水器进行排序
	int temp,maxRaius = 0;
	for (vector<int>::iterator it = houses.begin(); it != houses.end();++it ) {
		
		temp=minRadius(heaters, *it);
		maxRaius = maxRaius > temp ? maxRaius : temp;
		//cout << maxRaius << endl;
	}

	//cout << maxRaius << endl;
	return maxRaius;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38