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 ...
随机推荐
- 鸟哥的linux私房菜——第十三章学习(Linux 帐号管理与 ACLL 权限设置)
第十三章.Linux 帐号管理与 ACLL 权限设置 1.0).使用者识别码: UID 与 GID UID :User ID GID :group ID [root@study ~]# ll -d / ...
- Vue Component Registration All In One
Vue Component Registration All In One Vue 注册自定义组件 <template> <div class="back-to-top-c ...
- HTML a Tag All In One
HTML a Tag All In One HTML <a> target https://developer.mozilla.org/en-US/docs/Web/HTML/Elemen ...
- Web 安全漏洞 All In One
Web 安全漏洞 All In One Web 安全 & 漏洞 输入输出验证不充分 SQL 注入 XSS self-XSS CSRF 目录穿越 文件上传 代码注入 命令注入 信息漏洞 暴力破解 ...
- js var & let & const All In One
js var & let & const All In One js var & let & const 区别对比 var let const 区别 是否存在 hois ...
- Koa & node.js
KOA https://github.com/koajs/koa https://koajs.com/ $ nvm install 7 # node.js 7 + $ nvm install 10 $ ...
- c++ 动态设置函数
#include <iostream> #include <Windows.h> #include <TlHelp32.h> using namespace std ...
- 软件工程中的CI&CD
wiki 在软件工程中,CI/CD或CICD通常是指持续集成以及持续交付或持续部署的组合实践 持续集成 在软件工程中,持续集成(CI)是每天将所有开发人员的工作副本合并到共享主线中的一种做法.[1] ...
- 以代码为剑、数学为犁,SPC构建NGK算力生态体系
人类创造工具,工具反过来也改变着人类.以区块链为核心的货币革命率先吹响了对金融世界重塑的号角.以代码为剑.数学为犁,区块链构建了新的网路信任体系,这是一切的开始.基于此,NGK区块链技术将赋能实体产业 ...
- banner自用图床
放些常用的图做图床,也不在别的平台用.