-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathProcess.cpp
More file actions
60 lines (55 loc) · 1.27 KB
/
MathProcess.cpp
File metadata and controls
60 lines (55 loc) · 1.27 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
51
52
53
54
55
56
57
58
59
60
#include "include.h"
int PointToInt(cv::Point point)
{
if (point.x == 0 && point.y == 0)
return 1;
else if (point.x == 1 && point.y == 0)
return 2;
else if (point.x == 2 && point.y == 0)
return 3;
else if (point.x == 0 && point.y == 1)
return 4;
else if (point.x == 1 && point.y == 1)
return 5;
else if (point.x == 2 && point.y == 1)
return 6;
else if (point.x == 0 && point.y == 2)
return 7;
else if (point.x == 1 && point.y == 2)
return 8;
else
{
std::cerr << "Error: PointToInt failed." << std::endl;
return -1;
}
}
std::vector<int> PointsToInts(std::vector<Tile> &tiles)
{
std::vector<int> result;
for (int i = 0; i < tiles.size() - 1; i++)
{
result.push_back(PointToInt(tiles[i].position));
}
return result;
}
int CalculateInversions(std::vector<int> numbers)
{
int result = 0;
for (int i = 0; i < numbers.size(); i++)
{
int temp = 0;
for (int j = i + 1; j < numbers.size(); j++)
{
if (numbers[j] < numbers[i])
{
temp++;
}
else
{
continue;
}
}
result += temp;
}
return result;
}