CF1734B.Bright, Nice, Brilliant

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There is a pyramid which consists of nn floors. The floors are numbered from top to bottom in increasing order. In the pyramid, the ii -th floor consists of ii rooms.

Denote the jj -th room on the ii -th floor as (i,j)(i,j) . For all positive integers ii and jj such that 1ji<n1 \le j \le i < n , there are 22 one-way staircases which lead from (i,j)(i,j) to (i+1,j)(i+1,j) and from (i,j)(i,j) to (i+1,j+1)(i+1,j+1) respectively.

In each room you can either put a torch or leave it empty. Define the brightness of a room (i,j)(i, j) to be the number of rooms with a torch from which you can reach the room (i,j)(i, j) through a non-negative number of staircases.

For example, when n=5n=5 and torches are placed in the rooms (1,1)(1,1) , (2,1)(2,1) , (3,2)(3,2) , (4,1)(4,1) , (4,3)(4,3) , and (5,3)(5,3) , the pyramid can be illustrated as follows:

In the above picture, rooms with torches are colored in yellow, and empty rooms are white. The blue numbers in the bottom-right corner indicate the brightness of the rooms.

The room (4,2)(4,2) (the room with a star) has brightness 33 . In the picture below, the rooms from where you can reach (4,2)(4,2) have red border. The brightness is 33 since there are three torches among these rooms.

The pyramid is called nice if and only if for all floors, all rooms in the floor have the same brightness.

Define the brilliance of a nice pyramid to be the sum of brightness over the rooms (1,1)(1,1) , (2,1)(2,1) , (3,1)(3,1) , ..., (n,1)(n,1) .

Find an arrangement of torches in the pyramid, such that the resulting pyramid is nice and its brilliance is maximized.

We can show that an answer always exists. If there are multiple answers, output any one of them.

输入格式

The first line of the input contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single positive integer nn ( 1n5001 \le n \le 500 ) — the number of floors in the pyramid.

It is guaranteed that the sum of nn over all test cases does not exceed 500500 .

输出格式

For each test case, output nn lines, the arrangement of torches in the pyramid.

The ii -th line should contain ii integers, each separated with a space. The jj -th integer on the ii -th line should be 11 if room (i,j)(i,j) has a torch, and 00 otherwise.

We can show that an answer always exists. If there are multiple answers, output any one of them.

输入输出样例

  • 输入#1

    3
    1
    2
    3

    输出#1

    1 
    1 
    1 1 
    1 
    1 1 
    1 0 1

说明/提示

In the third test case, torches are placed in (1,1)(1,1) , (2,1)(2,1) , (2,2)(2,2) , (3,1)(3,1) , and (3,3)(3,3) .

The pyramid is nice as rooms on each floor have the same brightness. For example, all rooms on the third floor have brightness 33 .

The brilliance of the pyramid is 1+2+3=61+2+3 = 6 . It can be shown that no arrangements with n=3n=3 will have a greater brilliance.

首页