Advertisement
Korotkodul

mosh c 4

Feb 27th, 2022 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v){
  18. cout<<x<<' ';
  19. }
  20. cout<<"\n";
  21. }
  22.  
  23. void cvl(vector <ll> &v){
  24. for (auto x: v) cout<<x<<' ';
  25. cout<<"\n";
  26. }
  27.  
  28.  
  29. void cvv(vector <vector <int> > &v){
  30. for (auto x: v) cv(x);
  31. cout<<"\n";
  32. }
  33.  
  34. void cvb(vector <bool> v){
  35. for (bool x: v) cout<<x<<' ';
  36. cout<<"\n";
  37. }
  38.  
  39. void cvs(vector <string> v){
  40. for (auto a: v){
  41.  
  42. cout<<a<<"\n";
  43. }
  44. }
  45.  
  46.  
  47.  
  48. vector <vector <int> > smp; //sample
  49.  
  50. int n;
  51.  
  52. vector <vector <int> > pnt(int x, int y, vector <vector <int> > v){
  53. for (int j = 0; j < n;++j){
  54. v[x][j] = (v[x][j] + 1) % 2;
  55. }
  56. for (int i = 0 ; i < n;++i){
  57. v[i][y] = (v[i][y] + 1) % 2;
  58. }
  59. v[x][y] = (v[x][y] + 1) % 2;
  60. return v;
  61. }
  62.  
  63. vector <vector <pii> > ans;
  64.  
  65. void dfs(int dp, vector <vector <int> > v, vector <pii> cmd){
  66. /*cout<<"v = \n";
  67. cout<<"n = "<<n<<"\n";
  68. cvv(v);
  69. cout<<"smp=\n";
  70. cvv(smp);*/
  71. if (v == smp){
  72. //cout<<"dp = "<<dp<<"\n";
  73. //cout<<"v = \n";
  74. //cvv(v);
  75. //cout<<"OK\n";
  76. ans.push_back(cmd);
  77. return;
  78. }
  79. //cout<<"GO\n";
  80. if (dp == 3) return;
  81. vector <vector <int> > hlp;
  82. for (int x = 0; x < n;++x){
  83. for (int y = 0; y < n;++y){
  84. vector <pii> hlp_cmd = cmd;
  85. hlp_cmd.push_back({x,y});
  86. hlp = pnt(x,y,v);
  87. dfs(dp+1, hlp, hlp_cmd);
  88. }
  89. }
  90. }
  91.  
  92. bool compr(vector <pii> a, vector <pii> b){
  93. return a.size() < b.size();
  94. }
  95.  
  96.  
  97. int main()
  98. {
  99. ios::sync_with_stdio(0);
  100. cin.tie(0);
  101. cout.tie(0);
  102. int t; cin>>t;
  103. for (int act = 0; act < t;++act){
  104. // cout<<"ACT = "<<act<<"\n";
  105. cin>>n;
  106. smp.assign(n, vector <int>(n,0));
  107. for (int i = 0; i < n; ++i){
  108. for (int j = 0; j < n;++j) cin>>smp[i][j];
  109. }
  110. vector <pii> cmd = {};
  111. ans.clear();
  112. vector <vector <int> > v(n, vector <int> (n, 0));
  113. dfs(1, v, cmd); //так до 7-ми -- там перебираем вссе и смотрим -- dfs такой
  114. sort(ans.begin(), ans.end(), compr);
  115. cout<<ans[0].size()<<"\n";
  116. for (auto mv: ans[0]){
  117. cout<<mv.first<<' '<<mv.second<<"\n";
  118. }
  119. }
  120.  
  121. }
  122.  
  123. /*
  124. 3
  125. 4
  126. 0 0 1 0
  127. 0 0 1 0
  128. 1 1 1 1
  129. 0 0 1 0
  130. 4
  131. 0 1 1 0
  132. 1 1 0 1
  133. 1 0 1 1
  134. 0 1 1 0
  135. 3
  136. 1 1 0
  137. 1 0 1
  138. 0 1 1
  139. */
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement