-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (43 loc) · 1.41 KB
/
main.cpp
File metadata and controls
50 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* ---------------------------------------------------------------------------
** main.cpp
** Plays with the N Queens Las Vegas solver.
**
** Author: Santiago Gil Begué, NIA: 683482
** -------------------------------------------------------------------------*/
#include <iostream>
#include <nQueens.hpp>
#include <stdlib.h>
using namespace std;
int main()
{
// Initialize random seed.
srand(time(NULL));
/* 8 queens. Check that the amount of successes tends to p. */
NQueens board8(8);
int n = 0;
for (int i = 0; i < 200000; i++) {
n += board8.PlaceQueensLasVegas(8);
}
// Should be around p = 0’1293.
cout << "8 Queens probability of success with k=8: " << n / 200000.0 << "%" << endl << endl;
/* 39 Queens. Compare k values. */
NQueens board39(39);
for (int k = 22; k < 35; k++) {
clock_t begin = clock();
for (int i = 0; i < 200; i++) {
board39.RepPlaceQueensLasVegas(k);
}
clock_t end = clock();
cout << "39 Queens with k=" << k << ": " << (end - begin) * 1000 / 200.0 / CLOCKS_PER_SEC << "ms" << endl;
}
cout << endl;
/* 100 Queens. Find a solution. */
NQueens board100(100);
board100.RepPlaceQueensLasVegas(85);
board100.PrintBoard();
cout << endl;
/* 1000 Queens. Find a solution. */
NQueens board1000(1000);
board1000.RepPlaceQueensLasVegas(950);
board1000.PrintBoard();
}