【发布时间】:2016-02-11 16:54:24
【问题描述】:
我正在尝试解决这个 SPOJ 问题http://www.spoj.com/problems/BAISED/。
我的方法
for all elements in the preferred_position array
if(position>0&&position<=n)
if(position is unoccupied)
allocate position for user
else
reach the first free position in the array
for all elements whose preferred position is already filled
search both directions left,right to find nearest free_position
我尝试了许多测试用例,并得到了正确的结果,但我不知道我在哪里失败并得到了错误的答案。我根据贪婪标签选择了这个问题,我真的不知道在哪里应用贪婪技术。谁能给点灯?
【问题讨论】: