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 ...
随机推荐
- Gym 101464C - 计算几何+二分(uva1463)
不是很难,但是我觉得对代码能力的要求还是挺高的. 注意模块化. 因为是浮点数,所以二分用的很多很多. 参考 https://blog.csdn.net/njupt_lyy/article/detail ...
- Leetcode(83)-删除排序链表中的重复元素
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示例 2: 输入: 1->1->2->3-&g ...
- js Promise finally All In One
js Promise finally All In One finally let isLoading = true; fetch(myRequest).then(function(response) ...
- vue & this.$route & this.$router
vue & this.\(route & this.\)router const User = { template: '<div>User</div>' } ...
- Swift 5.3
Swift 5.3 https://swift.org/blog/ refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- ESLint All In One
ESLint All In One ESLint $ yarn add -D eslint .eslintrc.{js,yml,json} 优先级 .eslintrc .eslintrc.js .es ...
- Android Studio show whitespace & Android studio 设置注释缩进
Android Studio show whitespace & Android studio 设置注释缩进 https://github.com/xgqfrms/flutter/issues ...
- React In Depth
React In Depth React Component Lifecycle https://reactjs.org/docs/react-component.html https://react ...
- qt DateTime 计算时间
qdatetime doc 获取当前时间 QDateTime t1 = QDateTime::currentDateTime(); qDebug() << t1.toString(&quo ...
- 倒计时2天!2021 NGK新加坡区块链峰会与你不见不散!
1月31日14时,NGK将于新加坡召开"2021 NGK新加坡区块链峰会",并将在全球开启同步直播. 据了解,本次峰会将汇聚全球二十多位顶尖区块链专家学者,与NGK灵石技术团队 ...