社区讨论

第一次写英文题解,求挑错

学术版参与者 4已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@lo8ap3ig
此快照首次捕获于
2023/10/27 15:31
2 年前
此快照最后确认于
2023/10/27 15:31
2 年前
查看原帖
题目是一个墨西哥朋友给我的,所以题解得是全英文。
语法错误,算法伪证,术语错误等都可以挑刺。
先谢谢各位巨佬了 orz orz

题面:

Let us consider a long , quiet country road with houses scattered very sparsely along it .
Further , let us suppose that the residents of all these houses are avid cel phone users . You want to place cel phone base stations at certain points along the road , so that every house is within four miles of one of the base stations .
Give an efficient algorithm that achieves this goal , using as few base stations as possible . Prove correctness .

我的题解:

Above all, the distance between the adjacent houses may be very far, which makes the road too long to deal with. However, it doesn't matter how far it is as long as the distance is greater than 88 miles, because the stations between the two house can't reach both of them anyhow.
Thus, if it is greater than 88 , we can assume that it is exactly 99 .
For every house seated at aia_i , there are 99 points where a station can reach it. These points are at {ai4,ai3,...,ai+4}\{a_{i}-4,a_{i}-3,...,a_{i}+4\} . We can assume that the house contribute 11 coverage to these 99 points
Let c[i]c[i] be the contributions that the ii-th point received from nearby houses. By using a difference array, we can calculate cc with the time complexity of O(n)O(n).
To cover as many houses as possible with one station, we should place the station at the point whose c[i]c[i] is as great as possible. So we do that in the decreasing order of cc until all the houses are covered.
(Proof: if we place a station at where c[i]c[i] is smaller, it can't cover more houses than we did just now. So the needed stations can't be fewer. The answer must be inferior to that we had just now. )
To avoid covering a house unnecessarily repeatedly, we should mark the houses which have been covered. So every time we place a station at ii , we should mark the range [i4,i+4][i-4,i+4] as a no-station area.
(Proof: if we place a station outside the area, it can cover more houses than inside the area, and the house covered in the range won't be lost. )
To do this efficiently, we should push the <c[i],i><c[i],i> pairs into a heap in the decreasing order of c[i]c[i] . Every time we grab the top of the heap, pop it out, check if it's in a no-station area, place the station and mark the range if not.
To mark and check the range more efficiently, we can build a segment tree with tags, or just a binary indexed tree can tackle everthing.
The total time complexity is no more than O(nlogn)O(n\log n) .

回复

5 条回复,欢迎继续交流。

正在加载回复...