Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.programming    |    Programming issues that transcend langua    |    57,431 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 55,451 of 57,431    |
|    Darioes to All    |
|    Problem C++ gas tank refuel    |
|    13 Dec 21 20:54:47    |
   
   From: darioes078@gmail.com   
      
   Hi guys,   
      
      
      
   Im programing a new exerciese that i need to do for a college project, in C++.   
      
      
      
   That project consists in implementing an algorithm that just goes the minimal   
   ways, not like Dijkstra’s algorithm but something similar: You are have a   
   car, that needs to go from France to Corea and you need to refil your gas tank   
   . You need to pick    
   the minimal ways so that the car's fuel tank is as low as possible.   
      
      
      
   For example :   
      
      
      
   If the input is this:   
      
      
      
   From node 0 to node 1 cost 5   
      
      
      
   From node 0 to node 2 cost 4   
      
      
      
   From node 2 to node 1 cost 3   
      
      
      
   The algorithm should pick 0->2->1 . If you want to go from node 0 to node 1,   
   the maximum car's fuel tank is 4. Firstly it seems easy as you can just pick   
   the minimal ways, but in that example that doesn’t work :   
      
      
      
   From node 0 to node 1 cost 5   
      
      
      
   From node 0 to node 2 cost 4   
      
      
      
   From node 2 to node 1 cost 3   
      
      
      
   From node 2 to node 3 cost 6   
      
      
      
   From node 1 to node 3 cost 7   
      
      
      
   You should pick if you want to go from node 0 to node 3, 0->2->3, the car's   
   fuel tank is 6.   
      
      
      
   This is what I think should be done, but it isn’t working. Do you have any   
   ideas on how I can make it work?   
      
   int nodo = origen;   
   int minimo = INT_MAX;   
   while(nodo != destino){   
    for (int j = 0; j < totalNodos; j++){    
    if(!visitado[j] && coste[nodo][j] < minimo){   
    nodoMinimo = j;   
    minimo = coste[nodo][j];   
    }   
    }   
    nodo = v   
    if(minimoTotal < minimo ) minimoTotal = minimo;   
   }   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca