Double Matrix
time limit per test 1 second
memory limit per test 256 megabytes
题目链接http://codeforces.com/problemset/problem/1162/B
emmm,题目大意:给你两个矩阵,问你是否能通过交换对应位置的值使得两个矩阵都为严格递增矩阵(行递增,列递增)。。。。
想不到就没法做。。。想到了就很快。。。其实我们只需将最小值安排在一个矩阵,最大值安排在一个矩阵然后判断就行了,其合理性的判断就交给各位大佬了。。。
以下是AC代码:
#include <bits/stdc++.h>
using namespace std;
int a[60][60],b[60][60];
int main()
{
int n,m;
scanf ("%d%d",&n,&m);
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
scanf ("%d",&a[i][j]);
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
scanf ("%d",&b[i][j]);
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++){
int tmin=min(a[i][j],b[i][j]);
int tmax=max(a[i][j],b[i][j]);
a[i][j]=tmin;
b[i][j]=tmax;
}
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
if (a[i][j]<=a[i-1][j] || a[i][j]<=a[i][j-1] || b[i][j]<=b[i-1][j] || b[i][j]<=b[i][j-1]){
printf ("Impossible\n");
return 0;
}
printf ("Possible\n");
return 0;
}