Where is the flaw in my algorithm for consolidating gold mines?

后端 未结 2 638
栀梦
栀梦 2021-01-25 10:44

The setup is that, given a list of N objects like

class Mine
{
    public int Distance { get; set; } // from river
    public int Gold { get; set;          


        
2条回答
  •  感情败类
    2021-01-25 11:06

    When you consolidate mine i into mine j, the amount of gold in the mine j is increased. This makes consolidations from mine j to other mines more expensive potentially making the ordering of the mines by the move cost invalid. To fix this, you could re-sort the list of mines at the beginning of each iteration of your while-loop.

提交回复
热议问题