欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1816B.Grid Reconstruction
Grid Reconstruction
Consider a grid, where is an even integer. You may place the integers on the grid, using each integer exactly once.
A path is a sequence of cells achieved by starting at , then repeatedly walking either downwards or to the right, and stopping when is reached. The path should not extend beyond the grid.
The cost of a path is the alternating sum of the numbers written on the cells in a path. That is, let the numbers written on the cells be (in the order that it is visited), the cost of the path is $a_1 - a_2 + a_3 - a_4 + \ldots = um_{i=1}^k a_i \cdot (-1)^{i+1}$.
Construct a way to place the integers on the grid, such that the minimum cost over all paths from to is maximized. If there are multiple such grids that result in the maximum value, output any of them.
Input
The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first and the only line of each test case contains a single integer (, is even) — the number of the columns in the grid.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output lines, each containing integers — the desired grid. If there are multiple solutions, output any of them.
Note
In the first test case, there are only two paths from cell to cell . Their costs are and . Then the minimum cost is , which is the maximum possible value.
In the second test case, there are four paths from cell to cell . Their costs are , , , and . Then the minimum value is , which is the maximum possible value.
Samples
3
2
4
6
3 2
1 4
8 2 6 4
1 5 3 7
11 5 9 1 7 3
6 10 2 8 4 12
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |