• 题意
    • 给两个相同大小的矩阵,对应位置可以交换
    • 问是否能达到这样的状态
    • 两个矩阵中从左到右严格递增,从上到下严格递增(两维之间没有关联)
  • 题解
    • 直接一个放最小值,一个放最大值,直接判断
  • 代码
    • //#include<bits/stdc++.h>
      #include<algorithm>
      #include <iostream>
      #include   <fstream>
      #include  <cstdlib>
      #include  <cstring>
      #include  <cassert>
      #include   <cstdio>
      #include   <vector>
      #include   <string>
      #include    <cmath>
      #include    <queue>
      #include    <stack>
      #include      <set>
      #include      <map>
      using namespace std;
      #define P(a,b,c) make_pair(a,make_pair(b,c))
      #define rep(i,a,n) for (int i=a;i<=n;i++)
      #define per(i,a,n) for (int i=n;i>=a;i--)
      #define CLR(vis) memset(vis,0,sizeof(vis))
      #define MST(vis,pos) memset(vis,pos,sizeof(vis))
      #define pb push_back
      #define mp make_pair
      #define all(x) (x).begin(),(x).end()
      #define fi first
      #define se second
      #define SZ(x) ((int)(x).size())
      typedef pair<int,pair<int,int> >pii;
      typedef long long ll;
      typedef unsigned long long ull;
      const ll mod = 1000000007;
      const int INF = 0x3f3f3f3f;
      ll gcd(ll a, ll b) {
      	return b ? gcd(b, a%b) : a;
      }
      template<class T>inline void gmax(T &A, T B) {
      	(A<B)&&(A=B);//if(B>A)A=B;
      }
      template<class T>inline void gmin(T &A, T B) {
      	(A>B)&&(A=B);//if(B<A)A=B;
      }
      template <class T>
      inline bool scan_d(T &ret) {
      	char c;
      	int sgn;
      	if(c=getchar(),c==EOF) return 0; //EOF
      	while(c!='-'&&(c<'0'||c>'9')) c=getchar();
      	sgn=(c=='-')?-1:1;
      	ret=(c=='-')?0:(c-'0');
      	while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
      	ret*=sgn;
      	return 1;
      }
      inline void outt(int x) {
      	if(x>9) outt(x/10);
      	putchar(x%10+'0');
      }
      const int MAXN = 1e2+10;
      int a[MAXN][MAXN];
      int b[MAXN][MAXN];
      int main() {
      	int n,m;
      	cin>>n>>m;
      	CLR(a);
      	CLR(b);
      	rep(i,1,n) {
      		rep(j,1,m) {
      			scanf("%d",&a[i][j]);
      		}
      	}
      	rep(i,1,n) {
      		rep(j,1,m) {
      			scanf("%d",&b[i][j]);
      			if(b[i][j]<a[i][j]) {
      				swap(a[i][j],b[i][j]);
      			}
      		}
      	}
      	rep(i,1,n) {
      		rep(j,1,m) {
      			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]) {
      				puts("Impossible");
      				return 0;
      			}
      		}
      	}
      	puts("Possible");
      	return 0;
      }
      

发表评论

邮箱地址不会被公开。 必填项已用*标注