CF1699B.Almost Ternary Matrix

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two even integers nn and mm. Your task is to find any binary matrix aa with nn rows and mm columns where every cell (i,j)(i,j) has exactly two neighbours with a different value than ai,ja_{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)(x,y) are: (x−1,y)(x-1,y), (x,y+1)(x,y+1), (x+1,y)(x+1,y) and (x,y−1)(x,y-1).

It can be proven that under the given constraints, an answer always exists.

给你两个偶数 nn 和 mm。你的任务是构造任意一个大小为 nn 行 mm 列的 0-1 矩阵 aa,使得每个单元格 (i,j)(i,j) 恰好有两个相邻单元格的值与 ai,ja_{i,j} 不同。

矩阵中两个单元格被认为是相邻的,当且仅当它们共享一条边。更准确地说,单元格 (x,y)(x,y) 的相邻单元格为:(x−1,y)(x-1,y)、(x,y+1)(x,y+1)、(x+1,y)(x+1,y) 和 (x,y−1)(x,y-1)。

在给定约束下,可以证明答案一定存在。

输入格式

Each test contains multiple test cases. The first line of input contains a single integer tt (1≤t≤1001 \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 nn and mm (2≤n,m≤502 \le n,m \le 50) — the height and width of the binary matrix, respectively.

每个测试包含多个测试用例。输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。接下来的各行包含各测试用例的描述。

每个测试用例仅一行,包含两个偶数 nn 和 mm(2≤n,m≤502 \le n,m \le 50)—— 分别表示二进制矩阵的高度和宽度。

输出格式

For each test case, print nn lines, each of which contains mm numbers, equal to 00 or 11 — any binary matrix which satisfies the constraints described in the statement.

It can be proven that under the given constraints, an answer always exists.

对于每个测试用例,输出 nn 行,每行包含 mm 个数字(均为 00 或 11),即任意一个满足题目描述中约束条件的二进制矩阵。

可以证明,在给定约束条件下,答案一定存在。

输入输出样例

  • 输入#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 00, black means 11.

The binary matrix from the first test case

The binary matrix from the second test case

The binary matrix from the third test case

白色表示 00,黑色表示 11。

第一个测试用例的二进制矩阵

第二个测试用例的二进制矩阵

第三个测试用例的二进制矩阵

输入解题思路,AI测评打分。不知道怎么写?

首页