CF 1136C Nastya Is Transposing Matrices
题目分析
看了题目之后,第一想法:任意位置都可以倒置,要是枚举,铁定的超时。所以需要探索规律......
结果发现,任意的两个数,如果可以交换,其横纵坐标之和一定相同,所以我们只需要用一个数组存储横纵坐标相同的所以点的值,然后判断在的横纵坐标之和相同的情况下,这个数组中所含有的数是否完全一致,有一个数组中所含有的数不相同,那么肯定不满足条件。
代码区
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int Max = 5e2 + 10;
const int mod = 1e9 + 7;
int map1[2 * Max][Max]; //map[x][k],x表示横纵坐标之和为x,k表示第k个数,其中map[x][0]表示横纵坐标为x的点的总个数
int map2[2 * Max][Max];
bool cmp(int index)
{
for (int i = 1; i <= map1[index][0];i++)
{
if (map1[index][i] != map2[index][i])
return false;
}
return true;
}
int main()
{
int n, m;
while (scanf("%d%d", &n, &m) != EOF)
{
memset(map1, 0, sizeof(map1));
memset(map2, 0, sizeof(map2));
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m;j++)
{
int x;
scanf("%d", &x);
map1[i + j][++map1[i + j][0]] = x;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m;j++)
{
int x;
scanf("%d", &x);
map2[i + j][++map2[i + j][0]] = x;
}
}
bool ok = true;
for (int i = 2; i <= n + m;i++)
{
sort(map1[i] + 1, map1[i] + 1 + map1[i][0]); //让序列有序
sort(map2[i] + 1, map2[i] + 1 + map2[i][0]);
if (!cmp(i))
{
ok = false;
break;
}
}
if (ok)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}
CF 1136C Nastya Is Transposing Matrices的更多相关文章
- Codeforces 1136C - Nastya Is Transposing Matrices
题目链接:https://codeforces.com/problemset/problem/1136/C 题意: 给出 $n \times m$ 的矩阵 $A,B$,你可以对其中任意某个 $k \t ...
- Codeforces Round #546 (Div. 2) C. Nastya Is Transposing Matrices
C. Nastya Is Transposing Matrices time limit per test 1 second memory limit per test 256 megabytes i ...
- codeforces#1136 C. Nastya Is Transposing Matrices(找规律)
题意:给出两个n*m的矩阵,每次操作可以让一个正方形矩阵行列交换.问,在无限次操作下,第一个矩阵能否变成第二个矩阵 分析:先把操作限定在2*2的矩阵中.这样对角线上的元素就可以随意交换.也就是说,如果 ...
- C. Nastya Is Transposing Matrices
链接 [https://codeforces.com/contest/1136/problem/C] 题意 给你两个规模一样的矩阵 问是否可以通过不断选取A矩阵的子"方正"转置得到 ...
- Codeforces Round #546 C. Nastya Is Transposing Matrices
题面: 传送门 题目描述: 给出两个n x m的矩阵A,B.矩阵A可以把正方子矩阵进行"转置操作",问:可不可以对矩阵A进行多次这样的操作,使矩阵A变为矩阵B? 题目分析: 这 ...
- CF 1136B Nastya Is Playing Computer Games
题目链接:codeforces.com/problemset/problem/1136/B 题目分析 首先,读完题目,看了是个B题,嗯嗯...... 果断找规律,然后交了一波,居然过了!!! 代码区 ...
- CF 1136A 1136B 1136C 1136D 1136E(Round546ABCDE)题解
题目地址:https://codeforces.com/contest/1136 A: Nastya Is Reading a Book 题解:挨个判断即可,水题. 参考代码: #include< ...
- Codeforces 1136 - A/B/C/D/E - (Done)
链接:https://codeforces.com/contest/1136/ A - Nastya Is Reading a Book - [二分] #include<bits/stdc++. ...
- Codeforces Round #546 (Div. 2) 题解
Codeforces Round #546 (Div. 2) 题目链接:https://codeforces.com/contest/1136 A. Nastya Is Reading a Book ...
随机推荐
- 11、LineEdit与setCompleter自动补全
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug>//引入打印 ...
- C# 写日志的方法
public void WriteLog(string msg) { string filePath = AppDomain.CurrentDomain.BaseD ...
- 《剑指offer》算法题第四天
今日题目: 二进制中1的个数 数值的整数次方 调整数组顺序使奇数位于偶数前面 链表中倒数第K个节点 链表中环的入口节点 今天的题目都比较简单,但是前三道题都有不同的解法,4,5两题就不在这边讨论了,其 ...
- iview响应式布局
我想说,我要被逼成前端了. 之前没接触过响应式,这两天和另一位前端程序媛小小的研究了下.做了一个小例子,记录一下,方便以后使用. <template> <div> <Ro ...
- HGOI 20190711 题解
Problem A 矩阵第K小数 给定一个$n \times m$的矩阵,位置$A_{i,j} = i\times j$, 给出$Q$个询问,每一次查询矩阵中第$Q_i$小的数是多少. 对于100% ...
- 降维算法----PCA原理推导
1.从几何的角度去理解PCA降维 以平面坐标系为例,点的坐标是怎么来的? 图1 ...
- CodeForces 538F A Heap of Heaps
题意 给定一个长度为n的数组A,将它变为一颗k叉树(1 <= k <= n - 1)(堆的形式编号). 问对于每一个k,有多少个节点小于它的父节点. 解题 显然,最初的想法是暴力.因为树的 ...
- You Are Given a WASD-string...
C. You Are Given a WASD-string... 主要看的还是思维,分别求出在上下左右四个方向移动的最大幅度( mov_up, mov_down, mov_right, mov_le ...
- 对象转JSON字符串与json字符串转对象方法
JSON.stringify()[从一个对象中解析出字符串] JSON.parse()[从一个json字符串中解析出对象] var data = {"nums": 1, " ...
- PHP 最完美调用百度翻译接口代码示例 (原)
php调用百度翻译最新接口代码 问 题:写的过程遇到了一个问题,url拼接好的原翻译内容,appid,sign的地址直接输出到浏览器可以打开看到翻译后的返回值,但是各种curl,file_ ...