21537_HarmoniousMatrices

2022-5-16 18:19| 发布者: Hocassian| 查看: 37| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505403481599-Problem List-采集的数据-后羿采集器.html

Pro.ID

21537

Title

Harmonious Matrices

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21537

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Call an m × n matrix of bits "harmonious" if every cell in it has an even number of 1 bits as neighbors. A cell is a neighbor of itself, and also to the cells above, below, left, and right (if they exist). So the number of neighbors of a cell is at most five, but could be less, depending on where it is. The following is an harmonious 4 × 4 square of bits:

    0 1 0 01 1 1 00 0 0 11 1 0 1

    The task is to write a program which takes as input m and n, and produces an harmonious matrix of m rows and n columns of bits. The solution should avoid the all-zero matrix (if possible).

    输入

    The input will begin with a number Z ≤ 40 on a line by itself. This is followed by Z lines, each of which contains two space-separated positive integers m and n, each of which will be at most 40.

    输出

    Description

    Call an m × n matrix of bits "harmonious" if every cell in it has an even number of 1 bits as neighbors. A cell is a neighbor of itself, and also to the cells above, below, left, and right (if they exist). So the number of neighbors of a cell is at most five, but could be less, depending on where it is. The following is an harmonious 4 × 4 square of bits:

    0 1 0 01 1 1 00 0 0 11 1 0 1

    The task is to write a program which takes as input m and n, and produces an harmonious matrix of m rows and n columns of bits. The solution should avoid the all-zero matrix (if possible).

    Input

    The input will begin with a number Z ≤ 40 on a line by itself. This is followed by Z lines, each of which contains two space-separated positive integers m and n, each of which will be at most 40.

    Output

    For each input instance, the output will be an m × n harmonious matrix of 0s and 1s. The matrix should be non-zero if possible.

    Sample Input

    2
    4 4
    1 6

    Sample Output

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

    Source

    样例输入

    2
    4 4
    1 6

    样例输出

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

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部