Advertisement
Korotkodul

mosh c 2

Feb 27th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 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. vector <int> crd = {0, 1, 2, 3};
  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. int cnt = 0;
  65. void dfs(int dp, vector <vector <int> > v, vector <pii> cmd){
  66. if (v == smp){
  67. ans.push_back(cmd);
  68. }
  69. //cout<<"GO\n";
  70. if (dp == 5) return;
  71. vector <vector <int> > hlp;
  72. for (int x = 0; x < n;++x){
  73. for (int y = 0; y < n;++y){
  74. vector <pii> hlp_cmd = cmd;
  75. hlp_cmd.push_back({x,y});
  76. hlp = pnt(x,y,v);
  77. dfs(dp+1, hlp, hlp_cmd);
  78. }
  79. }
  80. }
  81.  
  82. bool compr(vector <pii> a, vector <pii> b){
  83. return a.size() < b.size();
  84. }
  85.  
  86.  
  87. int main()
  88. {
  89. /*ios::sync_with_stdio(0);
  90. cin.tie(0);
  91. cout.tie(0);*/
  92. cin>>n;
  93. smp.resize(n, vector <int>(n,0));
  94. for (int i = 0; i < n; ++i){
  95. for (int j = 0; j < n;++j) cin>>smp[i][j];
  96. }
  97. vector <pii> cmd = {};
  98. vector <vector <int> > v(n, vector <int> (n, 0));
  99. dfs(1, v, cmd); //так до 7-ми -- там перебираем вссе и смотрим -- dfs такой
  100. sort(ans.begin(), ans.end(), compr);
  101. cout<<ans[0].size()<<"\n";
  102. for (auto mv: ans[0]){
  103. cout<<mv.first<<' '<<mv.second<<"\n";
  104. }
  105. }
  106.  
  107. /*
  108. 4
  109. 0 0 1 0
  110. 0 0 1 0
  111. 1 1 1 1
  112. 0 0 1 0
  113. */
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement