Find position of non | C ++ implementation to find count of placing non - attacking rooks on the N x N chessboard ; Function to find the count of placing non - attacking rooks on the N x N chessboard ; Count of the Non - attacking rooks ; Printing lexographically smallest configuration ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findCountRooks ( int row [ ] , int col [ ] , int n , int k ) { int res = n - k ; cout << res << " STRNEWLINE " ; int ri = 0 , ci = 0 ; while ( res -- > 0 ) { while ( ri < k && row [ ri ] == 1 ) { ri ++ ; } while ( ci < k && col [ ci ] == 1 ) { ci ++ ; } cout << ( ri + 1 ) << " ▁ " << ( ci + 1 ) << " STRNEWLINE " ; ri ++ ; ci ++ ; } } int main ( ) { int n = 4 ; int k = 2 ; int row [ ] = { 1 , 2 } ; int col [ ] = { 4 , 2 } ; findCountRooks ( row , col , n , k ) ; return 0 ; }