Click
Here to go back to the homepage.
Hiding Places Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int cases;
cin >> cases;
while(cases--){
queue<pair<int, int>> q;
set<pair<int, int>> queued;
pair<bool, bool> board[8][8] = {};
char col, row;
cin >> col >> row;
col -= 'a';
row -= '1';
q.push({col, row});
int pieces = q.size();
int placed = 0, iterations = 0;
while(placed + q.size() < 64){
pieces = q.size();
iterations++;
for(int i = 0; i < pieces; i++){
placed++;
pair<int, int> coord = q.front();
int x = coord.first, y = coord.second;
q.pop();
board[x][y].first = true;
board[x][y].second = true;
if(x - 2 >= 0 && y - 1 >= 0 && !board[x - 2][y - 1].first && !board[x - 2][y - 1].second){
board[x - 2][y - 1].second = true;
q.push({x - 2, y - 1});
}
if(x - 2 >= 0 && y + 1 < 8 && !board[x - 2][y + 1].first && !board[x - 2][y + 1].second){
board[x - 2][y + 1].second = true;
q.push({x - 2, y + 1});
}
if(x + 2 < 8 && y - 1 >= 0 && !board[x + 2][y - 1].first && !board[x + 2][y - 1].second){
board[x + 2][y - 1].second = true;
q.push({x + 2, y - 1});
}
if(x + 2 < 8 && y + 1 < 8 && !board[x + 2][y + 1].first && !board[x + 2][y + 1].second){
board[x + 2][y + 1].second = true;
q.push({x + 2, y + 1});
}
if(x - 1 >= 0 && y - 2 >= 0 && !board[x - 1][y - 2].first && !board[x - 1][y - 2].second){
board[x - 1][y - 2].second = true;
q.push({x - 1, y - 2});
}
if(x - 1 >= 0 && y + 2 < 8 && !board[x - 1][y + 2].first && !board[x - 1][y + 2].second){
board[x - 1][y + 2].second = true;
q.push({x - 1, y + 2});
}
if(x + 1 < 8 && y - 2 >= 0 && !board[x + 1][y - 2].first && !board[x + 1][y - 2].second){
board[x + 1][y - 2].second = true;
q.push({x + 1, y - 2});
}
if(x + 1 < 8 && y + 2 < 8 && !board[x + 1][y + 2].first && !board[x + 1][y + 2].second){
board[x + 1][y + 2].second = true;
q.push({x + 1, y + 2});
}
}
}
cout << iterations << " ";
vector<pair<int, int>> v;
while(q.size()){
v.push_back(q.front());
q.pop();
}
sort(v.begin(), v.end(), [](const pair<int, int> &a, const pair<int, int> &b){
return a.second > b.second ? true : a.second < b.second ? false : a.first < b.first;
});
for(auto i : v){
cout << (char) (i.first + 'a') << (char) (i.second + '1') << " ";
}
cout << endl;
}
return 0;
}