MXN Puzzlesol:
\ (n*m\) the feasibility of a certain situation to reach another situation
It is possible to determine the parity of the number by reverse order.
Let's write the number of this \ (n*m-1\) in a column.
Source code#include<cstdio> #include <cstring> #include <algorithm>using namespace Std;int read () { int X=0,f=1;char ch= '; while (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch<= ' 9 ' &&ch>= ' 0 ') {x= (x<<3) + (x<<1) + (ch^ ' 0 '); Ch=getchar ();} return x*f;} const int N = + 2;int n,m;int a[n*n],tot;int tr[n*n];int lowbit (int x) {return x&-x;} void Modify (int p,int k) {for (int i=p;i<=tot;i+=lowbit (i)) {tr[i]+=k; }}int query (int p) {int ans=0; for (int i=p;i;i-=lowbit (i)) {ans+=tr[i]; } return ans; int main () {//Freopen ("Data.in", "R", stdin);//Freopen ("Sol.out", "w", stdout); while (1) {n=read (); M=read (); if (!n&&!m) break; memset (tr,0,sizeof (tr)); Tot=0;int POS; for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {int x;x=read (); if (x) a[++tot]=x; else pos=i; }} int muL=n*m; int ans=0; for (int i=tot;i;i--) {ans+=query (a[i]-1); Modify (a[i],1); } if (m%2==0) {ans+=n-pos; } if (ans%2==0) printf ("yes\n"); else printf ("no\n"); } return 0;}
MXN Puzzle-Reverse order the accessibility of the N*M digital problem scenario