• Source
    1. #include <bits/stdc++.h>
    2.  
    3. using namespace std;
    4.  
    5. typedef pair<int, int> ii;
    6.  
    7. #define MAXL 1002
    8.  
    9. int n, count1;
    10. vector<ii> pos0;
    11. vector<ii> pos1;
    12. bool ans[MAXL][MAXL];
    13.  
    14. void turn(int l, int c)
    15. {
    16. for (int j = 1; j <= n; j++) {
    17. if (ans[l][j])
    18. ans[l][j] = 0;
    19. else
    20. ans[l][j] = 1;
    21. }
    22. for (int i = 1; i <= n; i++) {
    23. if (i != l) {
    24. if (ans[i][c])
    25. ans[i][c] = 0;
    26. else
    27. ans[i][c] = 1;
    28. }
    29. }
    30. }
    31.  
    32. int main()
    33. {
    34. scanf("%d", &n);
    35.  
    36. char line[MAXL];
    37. for (int i = 1; i <= n; i++) {
    38. scanf(" %s", line);
    39.  
    40. for (int j = 0; j < strlen(line); j++) {
    41. if (line[j] == 'W') {
    42. pos1.push_back(make_pair(i, j + 1));
    43. count1++;
    44. }
    45. else
    46. pos0.push_back(make_pair(i, j + 1));
    47. }
    48. }
    49.  
    50. if (count1 <= (n * n) / 2) {
    51. for (int i = 0; i < pos1.size(); i++)
    52. turn(pos1[i].first, pos1[i].second);
    53. }
    54. else {
    55. for (int i = 0; i < pos0.size(); i++)
    56. turn(pos0[i].first, pos0[i].second);
    57. }
    58.  
    59. int tam = 0;
    60. for (int i = 1; i <= n; i++) {
    61. for (int j = 1; j <= n; j++) {
    62. if (ans[i][j])
    63. tam++;
    64. }
    65. }
    66.  
    67. if (tam <= (n * n) / 2) {
    68. printf("%d\n", tam);
    69. for (int i = 1; i <= n; i++) {
    70. for (int j = 1; j <= n; j++) {
    71. if (ans[i][j])
    72. printf("%d %d\n", i, j);
    73. }
    74. }
    75. }
    76. else {
    77. printf("%d\n", n * n - tam);
    78. for (int i = 1; i <= n; i++) {
    79. for (int j = 1; j <= n; j++) {
    80. if (!ans[i][j])
    81. printf("%d %d\n", i, j);
    82. }
    83. }
    84. }
    85. return 0;
    86. }
    87.