Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- bool c[8][8];
- int countFalses(int x, int y, bool c[8][8])
- {
- int count = 0;
- if (x + 1 <= 7 && y - 2 >= 0 && c[x + 1][y - 2] == false)
- ++count;
- if (x + 1 <= 7 && y + 2 <= 7 && c[x + 1][y + 2] == false)
- ++count;
- if (x + 2 <= 7 && y - 1 >= 0 && c[x + 2][y - 1] == false)
- ++count;
- if (x + 2 <= 7 && y + 1 <= 7 && c[x + 2][y + 1] == false)
- ++count;
- if (x - 1 >= 0 && y - 2 >= 0 && c[x - 1][y - 2] == false)
- ++count;
- if (x - 1 >= 0 && y + 2 <= 7 && c[x - 1][y + 2] == false)
- ++count;
- if (x - 2 >= 0 && y - 1 >= 0 && c[x - 2][y - 1] == false)
- ++count;
- if (x - 2 >= 0 && y + 1 <= 7 && c[x - 2][y + 1] == false)
- ++count;
- return count;
- }
- int main() {
- int x, y;
- cin >> x >> y;
- vector<int> v(8);
- for (int i = 1; i <= 64; ++i){
- c[x][y] = true;
- cout << i << ") " << x << " " << y << "\n";
- int min = 8;
- fill(v.begin(), v.end(), 8);
- if (x + 1 <= 7 && y + 2 <= 7 && c[x + 1][y + 2] == false) // 0
- v[0] = countFalses(x + 1, y + 2, c);
- if (x - 1 >= 0 && y + 2 <= 7 && c[x - 1][y + 2] == false) // 1
- v[1] = countFalses(x - 1, y + 2, c);
- if (x + 2 <= 7 && y + 1 <= 7 && c[x + 2][y + 1] == false) // 2
- v[2] = countFalses(x + 2, y + 1, c);
- if (x - 2 >= 0 && y + 1 <= 7 && c[x - 2][y + 1] == false) // 3
- v[3] = countFalses(x - 2, y + 1, c);
- if (x - 2 >= 0 && y - 1 >= 0 && c[x - 2][y - 1] == false) // 4
- v[4] = countFalses(x - 2, y - 1, c);
- if (x + 2 <= 7 && y - 1 >= 0 && c[x + 2][y - 1] == false) // 5
- v[5] = countFalses(x + 2, y - 1, c);
- if (x - 1 >= 0 && y - 2 >= 0 && c[x - 1][y - 2] == false) // 6
- v[6] = countFalses(x - 1, y - 2, c);
- if (x + 1 <= 7 && y - 2 >= 0 && c[x + 1][y - 2] == false) // 7
- v[7] = countFalses(x + 1, y - 2, c);
- for (int j = 0; j < 8; ++j)
- if(v[j]<min)
- min = v[j];
- if (v[0] == min) { // 0
- x += 1;
- y += 2;
- }
- else if (v[1] == min) { // 1
- x -= 1;
- y += 2;
- }
- else if (v[2] == min) { // 2
- x += 2;
- y += 1;
- }
- else if (v[3] == min) { // 3
- x -= 2;
- y += 1;
- }
- else if (v[4] == min) { // 4
- x -= 2;
- y -= 1;
- }
- else if (v[5] == min) { // 5
- x += 2;
- y -= 1;
- }
- else if (v[6] == min) { // 6
- x -= 1;
- y -= 2;
- }
- else if (v[7] == min) { // 7
- x += 1;
- y -= 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement