本文整理汇总了C++中Puzzle::solve方法的典型用法代码示例。如果您正苦于以下问题:C++ Puzzle::solve方法的具体用法?C++ Puzzle::solve怎么用?C++ Puzzle::solve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Puzzle
的用法示例。
在下文中一共展示了Puzzle::solve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printAndSolve
void printAndSolve( Puzzle sudoku ) {
cout << "\nThe given puzzle looks like this: \n\n";
sudoku.printBoard();
if (!sudoku.solve()) {
printf("Cannot solve puzzle\n");
exit(0);
}
cout << "\n\nThe solved puzzle looks like this: \n\n";
sudoku.printBoard();
cout << "\n\n";
}
示例2: main
int main(){
Puzzle sudoku;
cin >> sudoku;
cout << "Unsolved Puzzle:" << endl;
sudoku.display();
cout << endl;
//Solve returns true if solved, false if not.
if (sudoku.solve(0, 0)) {
cout << "Solved Puzzle:" << endl;
sudoku.display();
cout << endl;
}
else {
cout << "Puzzle is unsolvable." << endl;
}
return 0;
}
示例3: solve
void PartialSolver::solve()
{
while(!puzzles.empty())
{
Puzzle& front = puzzles.front();
///Clear points to find points for next puzzle
points.clear();
findPoints(front.puzzle);
list< pair<int,int> >::iterator it = points.begin();
for(;it!=points.end(); it++)
{
int row = (*it).first;
int col = (*it).second;
Puzzle back = Puzzle(front);
try
{
back.set(row, col, variable);
back.solve();
if(back.complete())
{
if(back.correct())
{
solved.push_back(back);
}
else
{
incorrect.push_back(back);
}
}
else
{
///If the puzzle is still partially correct continue search
if(partiallyCorrect(back))
puzzles.push_back(back);
}
} catch (bool& value) {
//incorrect.push_back(back);
}
}
puzzles.pop_front();
}
}