社区讨论
第一次写英文题解,求挑错
学术版参与者 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 miles, because the stations between the two house can't reach both of them anyhow.
Thus, if it is greater than , we can assume that it is exactly .
For every house seated at , there are points where a station can reach it. These points are at . We can assume that the house contribute coverage to these points
Let be the contributions that the -th point received from nearby houses. By using a difference array, we can calculate with the time complexity of .
To cover as many houses as possible with one station, we should place the station at the point whose is as great as possible. So we do that in the decreasing order of until all the houses are covered.
(Proof: if we place a station at where 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 , we should mark the range 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 pairs into a heap in the decreasing order of . 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 .
回复
共 5 条回复,欢迎继续交流。
正在加载回复...