Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8976689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:12:17+00:00 2026-06-15T19:12:17+00:00

The full problem description I am trying to solve can be found here: https://i.stack.imgur.com/o1cFn.png

  • 0

The full problem description I am trying to solve can be found here: https://i.stack.imgur.com/o1cFn.png

I am using a BFS and have created a RaceTrack object. The BFS queue setup is no problem, and this project would be cake (i think) if I only had to find the shortest path to one goal. But instead, I have to travel from the starting point through each checkpoint in order! Does anybody have any ideas how one would implement this with the standard idea of using a BFS? I’ll include my code, but keep in mind that it is VERY unfinished, and may make no sense. The “move” method is where the majority of the work needs to be done.

You’ll notice that I stopped at the if statement that tests if the space you move to is an integer.

Your suggestions are welcome.

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>

using namespace std;

class RaceTrack
{
public:
    RaceTrack() { count = 0;}

    bool isSolved()
    {
        if (solved == 1)
            return true;
        else
            return false;
    }

int solved;
string track;
int count;
set<char> prevChkPt;
};

int main()
{
    list<RaceTrack> q;  // queue for BFS
    set<RaceTrack> v; // set of visited tracks

    RaceTrack x;
    string sLine;
    vector<int> chkPts;
    int start;

    int w, h;
    int tmp = 0;

    cin >> w >> h;

for (int i = 0; i < h; i++)
{
cin >> sLine;
x.track += sLine;
}

q.push_back(x);

while (q.size() > 0 && x.isSolved() == false)
{
x = q.front();
q.pop_front();

start = x.track.find_first_of('0');

if (x.isSolved() == false && v.find(x) == v.end())
{
    v.insert(x);

    move (start, w, h, x, q, v, 'q');
    move (start, w, h, x, q, v, 'u');
    move (start, w, h, x, q, v, 'p');
    move (start, w, h, x, q, v, 'l');
    move (start, w, h, x, q, v, 'r');
    move (start, w, h, x, q, v, 'z');
    move (start, w, h, x, q, v, 'd');
    move (start, w, h, x, q, v, 'm');
}
}

if (x.isSolved == true)
    cout << x.count;
else
    cout << -1;

// for testing purposes only:
string quit;

// for testing purposes only:
cin >> quit;
if(quit == "quit")
    return 0;
}

void move (int start, int w, int h, RaceTrack x, list<RaceTrack> q, set<RaceTrack> v, char direction)
{
int d1, d2, d3, d4; // diagonal indices

if (direction == 'q') // diagonal top left
{
d1 = start - w - 1;

if (start % w == 0 || start < w)
    return;
else
{
    if (x.track[d1] == 'x')
        return;
    else if (x.track[d1] == ' ')
    {
        x.track[d1] = x.track[start];
        x.count++;
    }
    else if (isdigit(x.track[d1]))
        x.prevChkPt.insert(x.track[d1]);
}

}

if (v.find(x) == v.end())
    q.push_back(x);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:12:19+00:00Added an answer on June 15, 2026 at 7:12 pm

    As didierc mentioned, you may want to look at Dijkstra’s algorithm.

                                                             enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so here's the full description of the problem I'm having: I am trying
Post your best solutions! You can find the full problem description and examples here:
I've got an interesting box-model problem here. I have a header full of links,
I'm trying to read the ticker symbol at https://mtgox.com/api/0/data/ticker.php from my C++ application. I
Update 2011-12-28: Here's a blog post with a less vague description of the problem
I have a problem when trying to parse a webpage using jSoup. If I
I have been trying to parse this ( http://app.calvaryccm.com/mobile/android/v1/devos ) URL using a SAX
Problem: I have a symfony project with a database full of production data I
THIS IS THE FULL SCRIPT http://goo.gl/HoCxk I have a problem with this function: $('.message').click(function(){
Seems like cuke doesn't show the full error message (at least when problem occurs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.