Advertisement
Farjana_akter

Untitled

Mar 11th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int chess[5][5],n;
  4. bool ispossible(int i,int j)
  5. {
  6. if(chess[i][j]==1 || chess[i][j]==-1) return false;
  7. int ro,col,x,y;
  8. for(ro=i+1;ro<n && chess[ro][j]!=-1;ro++)
  9. {
  10. if(chess[ro][j]==1)
  11. return false;
  12. }
  13. for(ro=i-1; ro>=0 && chess[ro][j]!=-1; ro=ro-1)
  14. {
  15. if(chess[ro][j]==1) return false;
  16. }
  17. for(col=j+1; col<n && chess[i][col]!=-1; col++) {
  18. if(chess[i][col]==1) return false;
  19. }
  20. for(col=j-1; col>=0 && chess[i][col]!=-1; col=col-1) {
  21. if(chess[i][col]==1) return false;
  22. }
  23. return true;
  24. }
  25.  
  26. int rook()
  27. {
  28. int cnt=0,i,j,res;
  29.  
  30. for(i=0;i<n;i++)
  31. {
  32. for(j=0;j<n;j++)
  33. {
  34. if(ispossible(i,j)==true)
  35. { chess[i][j]=1;
  36. res=1+rook();
  37. cnt=max(cnt,res);
  38. chess[i][j]=0;
  39. }
  40. }
  41. }
  42. return cnt;
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48. while(cin>>n && n)
  49. {
  50. string s;
  51. memset(chess,0,sizeof(chess));
  52. int i,j;
  53. for(i=0;i<n;i++)
  54. {
  55. cin>>s;
  56. for(j=0;j<n;j++)
  57. {
  58. if(s[j]=='X')
  59. chess[i][j]=-1;
  60. }
  61. }
  62. int mn= rook();
  63. cout<<mn<<endl;
  64. }
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement