fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
  5. int dy[] = {0, -1, -1, -1, 0, 1, 1, 1};
  6. int dir[4][4] = {
  7. {6, 6, 5, 6},
  8. {7, 7, 5, 4},
  9. {0, 2, 2, 2},
  10. {1, 0, 4, 3},
  11. };
  12. bool color[4][4];
  13.  
  14. bool check() {
  15. for(int i = 0; i < 4; i++)
  16. for(int j = 0; j < 4; j++) {
  17. int ii = i+dy[dir[i][j]], jj = j+dx[dir[i][j]], b = 0, w = 0;
  18. while(ii >= 0 && ii < 4 && jj >= 0 && jj < 4) {
  19. if(color[ii][jj])
  20. w++;
  21. else
  22. b++;
  23. ii+=dy[dir[i][j]];
  24. jj+=dx[dir[i][j]];
  25. }
  26. if(!((color[i][j] && (w == 1)) || (!color[i][j] && (b == 2))))
  27. return false;
  28. }
  29. return true;
  30. }
  31.  
  32. int main() {
  33. for(int icolor = 0; icolor < (1<<16); icolor++) {
  34. int tmp = icolor;
  35. for(int i = 0; i < 4; i++)
  36. for(int j = 0; j < 4; j++) {
  37. color[i][j] = (tmp%2);
  38. tmp >>= 1;
  39. }
  40. if(check()) {
  41. for(int i = 0; i < 4; i++) {
  42. for(int j = 0; j < 4; j++)
  43. cout << (color[i][j]?"W":"B") << " ";
  44. cout << endl;
  45. }
  46. }
  47. }
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
W B B W 
W B B B 
B B B W 
B W W B