11.11 两轮电话面试,现在还没收到结果。每轮45分钟,上来直接coding没有任何BQ。 ;_;
第一轮:
大意:
In a unbounded 2D grid, you have a list of people(represented by points) and a list of bikes (represented by points as well).
Everyone want to get a bike that’s closest to him/her, butthere are situations when two people’s closest(Hamilton distance) bike is thesame. In this situation, the person further from the bike will have to choosenext unoccupied bike etc.
Basd on this rule, find a person-bike mapping that representswhich person will get which bike?
楼主一开始有点紧张头脑一热说了个Bi-BFS感觉有点凉 :/…
后来慢慢写优化的算法,大概是先计算所有人对所有自行车的距离,然后放到MinHeap里。每次pop一个globally最少距离,输出人-自行车的mapping,然后删除所有有关这个自行车的距离record。直到结束。
不知道是不是有更好的方法。
第二轮:
输入在二位平面上的一组点,输出两个点以至于两点连线可以使两边剩余点的数量一致。
这题在想的前几分钟想到一个有趣的解法,大致是随意选择一个点作为(0,0)然后根据此点把剩下所有点转化成极坐标,然后简单的取degree的median就可以了。