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 ...
- Leetcode(32)-最长有效括号
给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1: 输入: "(()" 输出: 2 解释: 最长有效括号子串为 "()&quo ...
- 『数据结构与算法』二叉查找树(BST)
微信搜索:码农StayUp 主页地址:https://gozhuyinglong.github.io 源码分享:https://github.com/gozhuyinglong/blog-demos ...
- sass文件编译(.scss->.css),使用ruby环境,在windows10,koala工具,Error: Invalid GBK character "\xE5"
1 注意事项: 问题描述: 请确保 Encoding.default_external = Encoding.find('utf-8') 是uft-8 编码! sass文件编译时候使用ruby环境,在 ...
- CVS、SVN、Git、GitHub :版本控制系统
1 1 1 Git常用命令 1 1 1 1 1 1 https://www.codecademy.com/learn/learn-git Learn Git You have now been int ...
- STAR 法则
STAR 法则 STAR: Situation, Task, Action, Result 一. 什么是 STAR 法则? STAR法则是情境(situation).任务(task).行动(actio ...
- AMP & PWA
AMP & PWA AMP is a web component framework to easily create user-first websites. stories. ads. e ...
- ts 修改readonly参数
readonly name = "xxx"; updateValueAndValidity(): void { // this.name = 'a'; (this as { nam ...
- 比特币大涨之际,VAST空投火爆来袭!
昨天特斯拉宣布投资了15亿美元的比特币,消息一出,币圈沸腾,比特币瞬间拉升,突破4万美元关口,现价46000美元!大涨20%,又刷新历史新高! 另外NGK项目热度最高的BGV也是不断刷新历史新高,数据 ...
- HTTP状态响应码解析
# HTTP响应状态码 ## 1xx:临时响应 #### 表示临时响应并需要请求者继续执行操作的状态代码. 100 **继续**请求者应当继续提出请求.服务器返回此代码表示已收到请求的第一部分,正在等 ...