在遍历加油站的时候,会将经过的x加油站放入优先队列,之后将x从数组中删掉,即用最后一个加油站来替代x;这时如果不 “i--”,则会漏掉检查原来的stop[n-1],则可能造成错误。

 1 if(stop[i].distence>=L)
 2             {
 3                 chosen.push(stop[i].fuelown);
 4                 if(i!=n-1)
 5                 {
 6                     stop[i].distence=stop[n-1].distence;
 7                     stop[i].fuelown=stop[n-1].fuelown;
 8                     i--;  //不加这个的话,会少检查一个原来的stop[n-1]。
 9                     n--;
10                 }
11                 else n--;
12             }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-12-21
  • 2021-09-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-08-26
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案