309562: CF1699B. Almost Ternary Matrix

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Almost Ternary Matrix

题意翻译

### 题目描述 给定偶数 $ n $ 和 $ m $,构造一个 $ n $ 行 $m $ 列只有0和1的方格矩阵,使得任意一个方格 $ (i,j) $ 正好有两个邻居方格的值不同与自己的值 $ a_{i,j} $ 。 公用一条边的两个方格视为邻居,准确为:方格 $ (x,y) $ 的邻居位置为 $ (x-1,y) $ , $ (x+1,y) $ , $ (x,y-1) $ , $ (x,y+1) $ 。 ### 输入格式 每个测试包含多组测试用例。第一行输入一个整数 $ t $ ( $ 1 \le t \le 100 $ ) ,即为测试用例的数量。 每个测试用例只有一行 $ n $ 和 $ m $ ,表示行数和列数。 ### 输出格式 对于每个测试用例,输出 $ n $ 行,每行 $ m $ 个数,每个数为0或1,即为构成的满足条件的方格矩阵。 可以证明,在给定条件下,答案必定存在。 ### 说明/提示 白代表0,黑代表1。 三张图分别表示样例的三个测试用例。

题目描述

You are given two even integers $ n $ and $ m $ . Your task is to find any binary matrix $ a $ with $ n $ rows and $ m $ columns where every cell $ (i,j) $ has exactly two neighbours with a different value than $ a_{i,j} $ . Two cells in the matrix are considered neighbours if and only if they share a side. More formally, the neighbours of cell $ (x,y) $ are: $ (x-1,y) $ , $ (x,y+1) $ , $ (x+1,y) $ and $ (x,y-1) $ . It can be proven that under the given constraints, an answer always exists.

输入输出格式

输入格式


Each test contains multiple test cases. The first line of input contains a single integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases. The following lines contain the descriptions of the test cases. The only line of each test case contains two even integers $ n $ and $ m $ ( $ 2 \le n,m \le 50 $ ) — the height and width of the binary matrix, respectively.

输出格式


For each test case, print $ n $ lines, each of which contains $ m $ numbers, equal to $ 0 $ or $ 1 $ — any binary matrix which satisfies the constraints described in the statement. It can be proven that under the given constraints, an answer always exists.

输入输出样例

输入样例 #1

3
2 4
2 2
4 4

输出样例 #1

1 0 0 1
0 1 1 0
1 0
0 1
1 0 1 0
0 0 1 1
1 1 0 0
0 1 0 1

说明

White means $ 0 $ , black means $ 1 $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1699B/e45c6cba9610d92a23c09f683cadfcf138054d1b.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1699B/7ff6e4e6c9a559b0e10cdc230a583d5a3442d4ca.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1699B/f610d75a7858ba6a9ddde3ee97e9dc52eaa2c58a.png)The binary matrix from the first test caseThe binary matrix from the second test caseThe binary matrix from the third test case

Input

题意翻译

### 题目描述 给定偶数 $ n $ 和 $ m $,构造一个 $ n $ 行 $m $ 列只有0和1的方格矩阵,使得任意一个方格 $ (i,j) $ 正好有两个邻居方格的值不同与自己的值 $ a_{i,j} $ 。 公用一条边的两个方格视为邻居,准确为:方格 $ (x,y) $ 的邻居位置为 $ (x-1,y) $ , $ (x+1,y) $ , $ (x,y-1) $ , $ (x,y+1) $ 。 ### 输入格式 每个测试包含多组测试用例。第一行输入一个整数 $ t $ ( $ 1 \le t \le 100 $ ) ,即为测试用例的数量。 每个测试用例只有一行 $ n $ 和 $ m $ ,表示行数和列数。 ### 输出格式 对于每个测试用例,输出 $ n $ 行,每行 $ m $ 个数,每个数为0或1,即为构成的满足条件的方格矩阵。 可以证明,在给定条件下,答案必定存在。 ### 说明/提示 白代表0,黑代表1。 三张图分别表示样例的三个测试用例。

Output

题目大意:给定两个偶数n和m,构造一个n行m列的01矩阵,使得每个方格恰有两个邻居方格的值与自己的值不同。

输入数据格式:第一行输入一个整数t(1≤t≤100),表示测试用例的数量。接下来每个测试用例只有一行n和m,表示行数和列数。

输出数据格式:对于每个测试用例,输出n行,每行m个数,每个数为0或1,即为构成的满足条件的方格矩阵。题目大意:给定两个偶数n和m,构造一个n行m列的01矩阵,使得每个方格恰有两个邻居方格的值与自己的值不同。 输入数据格式:第一行输入一个整数t(1≤t≤100),表示测试用例的数量。接下来每个测试用例只有一行n和m,表示行数和列数。 输出数据格式:对于每个测试用例,输出n行,每行m个数,每个数为0或1,即为构成的满足条件的方格矩阵。

加入题单

算法标签: