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 ...
随机推荐
- 【非原创】ZOJ - 4062 Plants vs. Zombies【二分】
题目:戳这里 题意:机器人走过一个花,可以给那个花浇水,给定步数下,问花的最小的最大能量值. 学习博客:戳这里 本人代码: 1 #include <bits/stdc++.h> 2 typ ...
- codeforces 1019B The hat 【交互题+二分搜索】
题目链接:戳这里 学习题解:戳这里
- unbuntu 安装 bochs
参考 https://www.cnblogs.com/HonkerYblogs/p/10285619.html https://blog.csdn.net/time4/article/details/ ...
- js map & Number
js map & Number const regionIds = `1,2,3`; // "1,2,3" regionIds.split(',').map(Number) ...
- How to Use RSS on Your Website
RSS feed 1 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- Flutter & release an iOS app
Flutter & release an iOS app https://flutter.dev/docs/deployment/ios .ipa https://en.wikipedia.o ...
- taro 禁用滚动事件
taro 禁用滚动事件 禁止 Modal 蒙层下面的页面的内容跟随滚动 https://github.com/NervJS/taro/issues/3980 https://github.com/Ne ...
- react fiber
react fiber https://github.com/acdlite/react-fiber-architecture https://github.com/facebook/react/is ...
- windows10 安装NASM
NASM官网 下载NASM NASM在线HTML文档 下载golink golink文档 NASM教程 in windows x64调用约定 x86调用约定 编码样式约定 在编写nasm时数字默认为1 ...
- 倒计时2天!2021 NGK新加坡区块链峰会与你不见不散!
1月31日14时,NGK将于新加坡召开"2021 NGK新加坡区块链峰会",并将在全球开启同步直播. 据了解,本次峰会将汇聚全球二十多位顶尖区块链专家学者,与NGK灵石技术团队 ...