Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v){
- cout<<x<<' ';
- }
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- vector <vector <int> > smp; //sample
- int n;
- vector <vector <int> > pnt(int x, int y, vector <vector <int> > v){
- for (int j = 0; j < n;++j){
- v[x][j] = (v[x][j] + 1) % 2;
- }
- for (int i = 0 ; i < n;++i){
- v[i][y] = (v[i][y] + 1) % 2;
- }
- v[x][y] = (v[x][y] + 1) % 2;
- return v;
- }
- vector <vector <pii> > ans;
- void dfs(int dp, vector <vector <int> > v, vector <pii> cmd){
- /*cout<<"v = \n";
- cout<<"n = "<<n<<"\n";
- cvv(v);
- cout<<"smp=\n";
- cvv(smp);*/
- if (v == smp){
- //cout<<"dp = "<<dp<<"\n";
- //cout<<"v = \n";
- //cvv(v);
- //cout<<"OK\n";
- ans.push_back(cmd);
- return;
- }
- //cout<<"GO\n";
- if (dp == 6) return;
- vector <vector <int> > hlp;
- for (int x = 0; x < n;++x){
- for (int y = 0; y < n;++y){
- vector <pii> hlp_cmd = cmd;
- hlp_cmd.push_back({x,y});
- hlp = pnt(x,y,v);
- dfs(dp+1, hlp, hlp_cmd);
- }
- }
- }
- bool compr(vector <pii> a, vector <pii> b){
- return a.size() < b.size();
- }
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- int t; cin>>t;
- for (int act = 0; act < t;++act){
- // cout<<"ACT = "<<act<<"\n";
- cin>>n;
- smp.resize(n);
- for (int i = 0; i < n;++i) smp[i].resize(n);
- for (int i = 0; i < n; ++i){
- for (int j = 0; j < n;++j) cin>>smp[i][j];
- }
- vector <pii> cmd = {};
- ans.clear();
- vector <vector <int> > v(n, vector <int> (n, 0));
- dfs(1, v, cmd); //так до 7-ми -- там перебираем вссе и смотрим -- dfs такой
- sort(ans.begin(), ans.end(), compr);
- if(ans.empty()) {
- cout<<"FUCK U\n";
- continue;
- }
- cout<<ans[0].size()<<"\n";
- for (auto mv: ans[0]){
- cout<<mv.first<<' '<<mv.second<<"\n";
- }
- }
- }
- /*
- 3
- 4
- 0 0 1 0
- 0 0 1 0
- 1 1 1 1
- 0 0 1 0
- 4
- 0 1 1 0
- 1 1 0 1
- 1 0 1 1
- 0 1 1 0
- 3
- 1 1 0
- 1 0 1
- 0 1 1
- */
Add Comment
Please, Sign In to add comment