-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
86 lines (63 loc) · 2.31 KB
/
main.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "hidato_generator.h"
#include "hidato_solver.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <chrono>
#include <iomanip>
using namespace std;
void printPuzzle(const vector<int> map, int width, int height) {
// find last number
int max = -1, digit = 1;
for (int i = 0; i < width * height; i++) if (map[i] > max) max = map[i];
while (max /= 10) digit += 1;
for (int i = 0; i < height; i++) {
cout << "\t";
for (int j = 0; j < width; j++) {
if (map[i * width + j] == -1) cout << setw(digit + 1) << " ";
else if (map[i * width + j] == 0) cout << setw(digit) << "." << " ";
else cout << setw(digit) << map[i * width + j] << " ";
}
cout << "\n";
}
}
int main() {
/// generate
ifstream input("input.txt");
int t;
input >> t;
while (t--) {
int width, height;
input >> width >> height;
vector<int> puzzle(width * height);
for (int i = 0; i < width * height; i++) input >> puzzle[i];
/// ----------
chrono::system_clock::time_point startTimePoint = chrono::system_clock::now();
cout << "generate start" << "\n";
Hidato::get()->generate(puzzle, width, height, 0.5f);
chrono::duration<float> elapsed = chrono::system_clock::now() - startTimePoint;
printPuzzle(puzzle, width, height);
cout << "generate end\nelapsed time: " << elapsed.count() << " sec" << "\n";
cout << "\n";
/// ----------
Solver solver;
startTimePoint = chrono::system_clock::now();
cout << "solve start" << "\n";
solver.solve(puzzle, height, width);
elapsed = chrono::system_clock::now() - startTimePoint;
printPuzzle(puzzle, width, height);
cout << "solve end\nelapsed time: " << elapsed.count() << " sec" << "\n";
cout << "\n";
/// ----------
switch(Hidato::get()->verify(puzzle, width, height)) {
case 1: cout << "correct" << endl; break;
case -1: cout << "different" << endl; break;
case -2: cout << "not connected" << endl; break;
default: cout << "error" << endl; break;
}
cout << endl;
/// ----------
}
input.close();
return 0;
}