ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Общий форум

is it simple?
Послано Sergey 14 ноя 2002 16:14
Breadth-First Search
1.    Introduction

For this program, the programmer is  required to solve the 8-puzzle
problem by implementing a Breadth-First Search algorithm in C++ . An
8-puzzle is a board containing 8 puzzle tiles and 9 tile positions.
Your program will take as an argument a string representing the
initial state of 8-puzzle. The string is in row major order, and a
space will denote the position of the blank tile. For instance...

2    8    3
1    6    4
7        5
Fig 1. An example initial state

would be encoded in the string "2831647 5"

Your program will end when it has successfully found a solution path
to the goal state...

1    2    3
8        4
7    6    5
Fig 2. The goal state

2. Specifications
PROGRAM NAME: Write all your source code in one file. Call the file
EightPuzzle.cc
INPUT: Your program will get its initial state from a command-line
argument. Invoking your program for the 8-puzzle depicted in figure 1
should look like...
EightPuzzle "2831647 5"
(don't forget the quotes around the state string!)
METHODS AND MESSAGES: Your program must contain the classes
EightPuzzle and
PuzzleBoard . EightPuzzle must have the methods doBFS to obtain a
solution and
printSolution to print all of the states in the solution path.
PuzzleBoard must have the
methods up , down , left , and right to move the blank tile. and
PuzzleBoard must also
implement the methods print to print the puzzle to cout and printPath
to print all states
starting from the initial state all the way down to the current state
(receiving object).
Your main( ) function will pass the initial state (given as a string
on the command line) to the constructor of an object of the
EightPuzzle class and call the doBFS method.

void main(int argc, char** argv) { EightPuzzle E(argv[1]);
// Find the solution. E.doBFS();
// Print the solution path. E.printSolution(); }

OUTPUT: The output of your program is to consist of the set of states
leading from the initial
state to the goal state. Print each of these states to the terminal.

3. Example
Running your program should look like...
>g++ EightPuzzle.cc -o EightPuzzle >EightPuzzle "123 64875"
1 2 3
   6 4
8 7 5

1 2 3
8 6 4
    7 5

1 2 3
 8 6 4
 7     5

1 2 3
8     8
 7 6 5
>