https://online.codingblocks.com/player/14796/content/5065?s=3194
can anyone provide some hint for it
Funky chess board hint
Hey Kushagra, you can solve this problem using recursion/dfs fashion. once you visit a cell, then visit all the cells that can be visited from this cell and also visit the cells that can be further visited from the next reachable cells.
but i havent learnt dfs yet
You can solve it using recursion only.
Problem Name- Funky Chess Board
Problem Link-https://hack.codingblocks.com/practice/p/107/715
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define mk make_pair
ll n=0;
ll chessBoard[10][10]={0};
ll start_i=-1,start_j=-1;
ll notReachableCells=0;
void solve(){
queue<pair<ll,ll>> q;
q.push(mk(start_i,start_j));
chessBoard[start_i][start_j]=-1;
while(!q.empty()){
pair<ll,ll> t=q.front();
q.pop();
ll r=t.first,c=t.second;
if(r-2>=0 && r-2<=9 && c-1>=0 && c-1<=9 && chessBoard[r-2][c-1]==1){
chessBoard[r-2][c-1]=-1;
q.push(mk(r-2,c-1));
//continue;
}
if(r-2>=0 && r-2<=9 && c+1>=0 && c+1<=9 && chessBoard[r-2][c+1]==1){
chessBoard[r-2][c+1]=-1;
q.push(mk(r-2,c+1));
//continue;
}
if(r-1>=0 && r-1<=9 && c-2>=0 && c-2<=9 && chessBoard[r-1][c-2]==1){
chessBoard[r-1][c-2]=-1;
q.push(mk(r-1,c-2));
//continue;
}
if(r-1>=0 && r-1<=9 && c+2>=0 && c+2<=9 && chessBoard[r-1][c+2]==1){
chessBoard[r-1][c+2]=-1;
q.push(mk(r-1,c+2));
//continue;
}
if(r+1>=0 && r+1<=9 && c-2>=0 && c-2<=9 && chessBoard[r+1][c-2]==1){
chessBoard[r+1][c-2]=-1;
q.push(mk(r+1,c-2));
//continue;
}
if(r+1>=0 && r+1<=9 && c+2>=0 && c+2<=9 && chessBoard[r+1][c+2]==1){
chessBoard[r+1][c+2]=-1;
q.push(mk(r+1,c+2));
//continue;
}
if(r+2>=0 && r+2<=9 && c-1>=0 && c-1<=9 && chessBoard[r+2][c-1]==1){
chessBoard[r+2][c-1]=-1;
q.push(mk(r+2,c-1));
//continue;
}
if(r+2>=0 && r+2<=9 && c+1>=0 && c+1<=9 && chessBoard[r+2][c+1]==1){
chessBoard[r+2][c+1]=-1;
q.push(mk(r+2,c+1));
//continue;
}
}
for(ll i=0;i<10;i++){
for(ll j=0;j<10;j++){
if(chessBoard[i][j]==1)
notReachableCells++;
}
}
}
int main(){
sl(n);
for(ll i=0;i<n;++i){
for(ll j=0;j<n;++j){
sl(chessBoard[i][j]);
if(start_i==-1 && start_j==-1 && chessBoard[i][j]==1){
start_i=i;start_j=j;
}
}
}
solve();
cout<<notReachableCells<<endl;
/for(int i=0;i<10;++i){
for(int j=0;j<10;++j){
cout<<chessBoard[i][j]<<" ";
}
cout<<endl;
}/
return 0;
}
Sir this is my code for the Solution. Only 1 test case accepted. What i need to consider to Minimize this Number(output).