Test instructions
Give a n*n 01 matrix and ask if it is possible to exchange rows to make
The number on the main diagonal is 1.
If you can output the exchange process, if not output-1
Ideas:
Linear algebra has been studied, and row and column exchanges do not change the rank of matrices
Three rank equal
If we can change the number to the main diagonal, it's 1.
The original matrix must be full-rank
/************************************************//author:d evil//created TIME:2016/5/10 21:49:26//*********** ************************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn= the; Vector<int>Eg[n];intlink[n],a[n*n],b[n*N];BOOLVis[n];BOOLDfsintu) { for(intI=0; I<eg[u].size (); i++) { intv=Eg[u][i]; if(!Vis[v]) {Vis[v]=1; if(link[v]==-1||DFS (Link[v])) {Link[v]=u; return 1; } } } return 0;}intMain () {//freopen ("In.txt", "R", stdin); intn,x; while(~SCANF ("%d",&N) {memset (link),-1,sizeof(link)); for(intI=1; i<=n;i++) eg[i].clear (); for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) {scanf ("%d",&x); if(x) Eg[i].push_back (j); } } intans=0; for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); Ans+=DFS (i); } if(ans<N) {printf ("-1\n"); Continue; } intCnt=0, J; for(intI=1; i<=n;i++) { for(j=1; j<=n;j++) if(link[j]==i) Break; if(j!=i) {a[cnt]=i; B[cnt++]=J; Swap (link[j],link[i]); }} printf ("%d\n", CNT); for(intI=0; i<cnt;i++) printf ("C%d%d\n", A[i],b[i]); } return 0;}
HDU2819 Swap (binary match + output result)