95 lines
1.3 KiB
C++
95 lines
1.3 KiB
C++
#include<cstdio>
|
|
#include<string.h>
|
|
#include<iostream>
|
|
using namespace std;
|
|
const int N=1e3+5;
|
|
int a[N][N];
|
|
bool b[N];
|
|
int n;
|
|
bool cmp(int k)
|
|
{
|
|
for(int i=1;i<k;i++)
|
|
{
|
|
if(a[k][i]>a[i][k])
|
|
{
|
|
// printf("%d(i xiao):%d %d\n",k,i,0^b[i]);
|
|
return 0^b[i];
|
|
}
|
|
else if(a[k][i]<a[i][k])
|
|
{
|
|
// printf("%d(i big):%d %d\n",k,i,1^b[i]);
|
|
return 1^b[i];
|
|
}
|
|
}
|
|
for(int i=k+1;i<=n;i++)
|
|
{
|
|
if(a[k][i]<a[i][k])
|
|
{
|
|
// printf("%d(i xiao):%d %d\n",k,i,0^b[i]);
|
|
return 0^b[i];
|
|
}
|
|
else if(a[k][i]>a[i][k])
|
|
{
|
|
// printf("%d(i big):%d %d\n",k,i,1^b[i]);
|
|
return 1^b[i];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
int main()
|
|
{
|
|
int t;
|
|
int k;
|
|
scanf("%d",&t);
|
|
while(t--)
|
|
{
|
|
scanf("%d",&n);
|
|
memset(b,0,sizeof(bool)*(n+1));
|
|
for(int i=1; i<=n; i++)
|
|
{
|
|
for(int j=1; j<=n; j++)
|
|
{
|
|
scanf("%d",&a[i][j]);
|
|
// a[i][j]=(i-1)*n+j;
|
|
// printf("%02d ",a[i][j]);
|
|
}
|
|
// printf("\n");
|
|
}
|
|
for(k=2; k<=n; k++)
|
|
{
|
|
if(a[k][1]<a[1][k])
|
|
{
|
|
b[k]=1;
|
|
}
|
|
}
|
|
for(k=2; k<=n; k++)
|
|
{
|
|
if(!b[k])
|
|
{
|
|
if(cmp(k))
|
|
b[k]=1;
|
|
}
|
|
}
|
|
for(k=2; k<=n; k++)
|
|
{
|
|
if(b[k])
|
|
{
|
|
for(int i=1;i<=n;i++)
|
|
{
|
|
int tmp=a[k][i];
|
|
a[k][i]=a[i][k];
|
|
a[i][k]=tmp;
|
|
}
|
|
}
|
|
}
|
|
for(int i=1; i<=n; i++)
|
|
{
|
|
for(int j=1; j<=n; j++)
|
|
{
|
|
printf("%d ",a[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
}
|
|
}
|