Codeforces Round #557 B. Double Matrix
题面:
题目描述:
题目分析:
1 #include <iostream>
2 #include <cstdio>
3 using namespace std;
4 int n, m;
5 int a[55][55], b[55][55];
6
7 bool check(int a[][55], int mode){ //mode == 1: 对矩阵a进行操作, mode == 2: 检查是否合法
8 for(int i = 0; i < n; i++){
9 for(int j = 0; j < m; j++){
10 if(i > 0 && a[i-1][j] >= a[i][j]){
11 if(mode) swap(a[i][j], b[i][j]);
12 else return false;
13 }
14 if(j > 0 && a[i][j-1] >= a[i][j]){
15 if(mode) swap(a[i][j], b[i][j]);
16 else return false;
17 }
18 }
19 }
20 return true;
21 }
22
23 void init(int a[][55]){
24 for(int i = 0; i < n; i++){
25 for(int j = 0; j < m; j++){
26 scanf("%d", &a[i][j]);
27 }
28 }
29 }
30
31 int main(){
32 scanf("%d%d", &n, &m);
33 init(a); init(b);
34
35 for(int i = 0; i < n; i++){
36 for(int j = 0; j < m; j++){
37 if(a[i][j] > b[i][j]){
38 swap(a[i][j], b[i][j]); //第一步
39 }
40 }
41 }
42
43 //第二步
44 check(a, 1); //需要交换就交换
45
46 if(!check(a, 0) || !check(b, 0)){ //检查矩阵a和矩阵b是否合法
47 printf("Impossible\n");
48 return 0;
49 }
50 printf("Possible\n");
51 return 0;
52 }
Codeforces Round #557 B. Double Matrix的更多相关文章
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #557 题解【更完了】
Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...
- Educational Codeforces Round 9 F. Magic Matrix 最小生成树
F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a mat ...
- Codeforces Round #557 (Div. 1)
A.直接做. #include<vector> #include<cstdio> #include<cstring> #include<iostream> ...
- Codeforces Round #557 Div. 1 based on Forethought Future Cup - Final Round
A:开场就读错题.读对了之后也没啥好说的. #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- Educational Codeforces Round 40 C. Matrix Walk( 思维)
Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- ElasticSearch 7.x 学习
目录 ElasticSearch 7.x 一.前言 1.1.正向索引和倒排索引 1.1.1.正向索引 1.1.2.倒排索引 二.安装 三.ES 基本概念 3.1.索引 3.2.文档 3.4.mappi ...
- Hexo-使用阿里iconfont图标
Hexo-使用阿里iconfont图标 因为使用hexo搭建的博客中,大家并不懂都有什么图标,fa fa-xx就懵了,不知道都有什么. 首先,fa fa-xxx中的图标可以在 图标库 中寻找. (上面 ...
- vue & async mounted
vue & async mounted refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- array group by key javascript
array group by key javascript calendar Array.reduce https://developer.mozilla.org/en-US/docs/Web/Jav ...
- Intersection Observer
Intersection Observer Intersection Observer API https://developer.mozilla.org/en-US/docs/Web/API/Int ...
- Typescript & React & optional parameters & default parameters
Typescript & React & optional parameters & default parameters Typescript & optional ...
- Node.js & LTS
Node.js & LTS 2020 https://nodejs.org/en/about/releases/ https://raw.githubusercontent.com/nodej ...
- 统一数据管理工具 —— CloudQuery v1.3.3 上线!
前言 岁末临近,让我们跟随着新春的脚步,一起去看看 CloudQuery 今年最后一次更新吧! 新增功能 一.Oracle - 查看表结构 Oracle 数据源中,可查看各表结构信息(列详情和表注释等 ...
- Git 学习相关笔记
Git Bash 相关命令学 基础概念 参考: https://www.cnblogs.com/gaoht/p/9087070.html https://www.runoob.com/git/git- ...
- 深入理解Linux TCP backlog
本文转载自深入理解Linux TCP backlog 当应用程序调用listen系统调用让一个socket进入LISTEN状态时,需要指定一个参数:backlog.这个参数经常被描述为,新连接队列的长 ...