1.题目描述:
2.题意:
略。
3.思路:
数学+思维。 【这谁会做啊!】 首先我们观察,对于一个空格它有两种操作:左右移动,上下移动。我们要确定两个矩阵是否一样,就要看在这两种操作下都不变的量,然后这个量就是我们对比的依据。一般对于这种矩阵题,都可以化成一个一维的串。如果化成串之后,我们学过的具有某些特质的数【目前为止】就只有:逆序数。我们发现:上下操作不改变逆序数的奇偶,左右操作不改变逆序数的大小。于是我们有了一个指标——序列的逆序数。逆序数奇偶性相同,则可以。否则,则不行。
4.代码:
//AcWing 108. 奇数码问题
//#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
//#include<random>
#include<cstdlib>
#include<ctime>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define FAST ios::sync_with_stdio(false)
#define DEV_RND ((int)rand()*RAND_MAX+rand())
#define RND(L,R) (DEV_RND%((R)-(L)+1)+(L))
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,n,a) for(int i=n-1;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define li inline
#define re register
using namespace std;
//typedef uniform_int_distribution<int> RNDI;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int Hash = 131;//13331
const int maxn = 250000+10;
const int maxm = 100000+5;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-7;
const double pi = acos(-1);
//int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//li int f(int x){return x==par[x]?par[x]:par[x]=f(par[x]);}
//mt19937 eng(time(0));
//li int RND(int L,int R){RNDI rnd(L,R);return rnd(eng);}
li ll lowbit(ll x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
li ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res%MOD;}
li ll qmul(ll a,ll b,ll MOD=mod){return (a*b-(ll)((long double)a/MOD*b)*MOD+MOD)%MOD;}
li ll inv(ll x,ll p){return qpow(x,p-2,p);}
li ll jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
db f(db x){return x;}
li db sim(db l,db r){return (f(l)+4.*f((l+r)/2.)+f(r))*(r-l)/6.;}
db asr(db l,db r,db ans,db eps){db m=l+(r-l)/2.,L=sim(l,m),R=sim(m,r);return fabs(L+R-ans)<=15.*eps?L+R+(L+R-ans)/15.:asr(l,m,L,eps/2)+asr(m,r,R,eps/2);}
db asr(db l,db r,db eps){return asr(l,r,sim(l,r),eps);}
namespace IO
{
li ll read()
{
ll x=0,sign=1;char c=getchar();
while(c>'9'||c<'0') {if(c=='-') sign=-1;c=getchar();}
while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();
return x*sign;
}
template<typename T>
li void write(T x,char t='\n')
{
if(x<0){x=-x;putchar('-');};
static int sta[25];int top=0;
do{sta[top++]=x%10;}while(x/=10);
while(top) putchar(sta[--top]+'0');
putchar(t);
}
}
using namespace IO;
/*-------------head-------------*/
//
int n,x;
ll cnt;
int nums[maxn],tmp[maxn];
void merge_sort(int l,int r)
{
if(l==r) return;
int mid=(l+r)>>1;
merge_sort(l,mid);
merge_sort(mid+1,r);
int L=l,R=mid+1,cnt=l;
while(L<=mid&&R<=r)
{
if(nums[L]<=nums[R]) tmp[cnt++]=nums[L++];
else
{
tmp[cnt++]=nums[R++];
cnt+=mid-L+1;
}
}
while(L<=mid) tmp[cnt++]=nums[L++];
while(R<=r) tmp[cnt++]=nums[R++];
rep(i,l,r+1) nums[i]=tmp[i];
}
li void solve()
{
int num=0;
rep(i,0,n*n) if(x=read(),x) nums[num++]=x;
merge_sort(0,n*n-1);
bool cnt1=cnt&1;
mem(nums,0);
cnt=0;num=0;
rep(i,0,n*n) if(x=read(),x) nums[num++]=x;
merge_sort(0,n*n-1);
bool cnt2=cnt&1;
puts(cnt1==cnt2?"TAK":"NIE");
//puts("");
}
int main()
{
//srand(time(0));
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//for(int QwQ=read();QwQ;QwQ--) solve();
while(~scanf("%d",&n)) solve();
return 0;
}