Codeforces-Round#546(Div.2)-C-Nastya Is Transposing Matrices

这个题算是找规律吧,你只要相信通过[i,j]和[j,i]交换有限次必定能得到所有符合题意的矩阵这个结论,那么直接判断两个矩阵对应位置是否相等就行了。

这里唯一需要处理的就是n和m不一定相等,所以我们可以把两个矩阵线性化,再去判断。

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <string>

using namespace std;

const int maxn=505;
int n,m;
int a[maxn][maxn],b[maxn][maxn];
map<int,int> mp[2*maxn];

int main(){
    scanf("%d%d",&n,&m);
    int flag=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            scanf("%d",&a[i][j]);
            mp[i+j][a[i][j]]++;
        }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            scanf("%d",&b[i][j]);
            mp[i+j][b[i][j]]--;
            if(mp[i+j][b[i][j]]<0) flag=1;
        }
    if(flag) printf("NO\n");
    else printf("YES\n");
    return 0;
}

  

posted @ 2019-03-20 22:14  alusang  阅读(77)  评论(0编辑  收藏  举报