?? main.cpp.bak
字號:
#include<iostream.h>
#include"EightQueens.h"
#include"time.h"
void main()
/*
Pre: The user enters a valid board size.
Post: All solutions to the n-queens puzzle for the selected
board size are printed.
Uses: The class Queens and the recursive function solve_from.
*/
{
int board_size;
void solve_from(Queens &configuration);
void print_information();
print_information();
cout << "What is the size of the board? " << flush;
cin >> board_size;
double start=time(NULL);
if (board_size < 0 || board_size > max_board)
cout << "The number must be between 0 and " << max_board << endl;
else {
Queens configuration(board_size); // Initialize empty configuration.
solve_from(configuration); // Find all solutions extending configuration.
}
double end=time(NULL);
cout<<"It takes time: "<<(end-start)<<"(s)"<<endl;
}
void print_information()
{
cout<<"This is the Queens game."<<endl;
}
void solve_from(Queens &configuration)
/*
Pre: The Queens configuration represents a partially completed
arrangement of nonattacking queens on a chessboard.
Post: All n-queens solutions that extend the given configuration are printed.
The configuration is restored to its initial state.
Uses: The class Queens and the function solve_from, recursively.
*/
{
if (configuration.is_solved()) configuration.print();
else
for (int col = 0; col < configuration.board_size; col++)
if (configuration.unguarded(col)) {
configuration.insert(col);
solve_from(configuration); // Recursively continue to add queens.
configuration.remove(col);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -