Computer Science Canada Help question |
Author: | Panphobia [ Fri Dec 21, 2012 10:25 pm ] | ||||
Post subject: | Help question | ||||
Since the next 2 dwites have been canceled i have just been doing all the questions, and I hope to do them all during the winter break, I have had one problem with this question http://dwite.org/questions/haunted_house.html , I will explain what i think is wrong, when a map like this
|
Author: | Panphobia [ Wed Dec 26, 2012 9:39 pm ] |
Post subject: | RE:Help question |
what I am really asking is, is there a way to make a bfs not give you the shortest path, but the optimal path with your restrictions? |
Author: | Tony [ Wed Dec 26, 2012 10:46 pm ] |
Post subject: | RE:Help question |
The shorted path _is_ the optimal path. Quote: The output file OUT5.txt will contain 5 lines of output, each a pair of non-negative integers C and S. C is the maximum number of candy pieces that Billy can collect. S is the minumum number of steps to do so. The tricky part to this question is that as you collect candy, new nodes and edges appear in the graph. In the example that you give, the answer would be the same event if all the doors were open spaces instead (so regular BFS). |
Author: | Panphobia [ Thu Dec 27, 2012 12:53 am ] |
Post subject: | RE:Help question |
What I meant by shortest path was the path without counting in candies on the way, and by optimal I meant the path with all attainable candies |
Author: | Panphobia [ Thu Dec 27, 2012 2:06 am ] | ||
Post subject: | Re: Help question | ||
would you guys tell me if I am overthinking it? now I have changed what i store in the queue, and the return value of my bfs, what I am trying to do now, is flood through the possible candies and figure out how many there are, and THEN, store the number of start points, call the bfs with the current start positions, and accumulate the shortest path to each candy, so basically i start at B and then I get the shortest path to the nearest candy, mark that position as visited, set the steps to 0, and then make the point where you found the candy, your new start point and check for the closest star from there, and then so on, for all of the possible candies, here is my code
|
Author: | Tony [ Thu Dec 27, 2012 1:30 pm ] |
Post subject: | RE:Help question |
This is known as a Greedy Algorithm. It will probably work in most of the cases. An exception would be something like: Quote: *.B*** Where the optimal path involves going for the candy on the left first. |
Author: | Panphobia [ Thu Dec 27, 2012 6:24 pm ] |
Post subject: | RE:Help question |
So I solved the problem partly with the greedy algorithm but I would like to know how to solve it by putting the number of candies in a queue and keep track of it that way, kinda lost with that |