CF291D.Parallel Programming

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarpus has a computer with n processors. Also, his computer has n memory cells. We'll consider the processors numbered by integers from 1 to n and that the memory cells are consecutively numbered by integers from 1 to n.

Polycarpus needs to come up with a parallel program model. For each memory cell number i this program must record the value n - i to this cell. In other words, for each cell you've got to find the distance to cell n.

Let's denote the value that is written in the i-th cell as a__i. Initially, a__i = 1 (1 ≤ i < n) and a__n = 0. We will consider that only processor i can write values in the memory cell number i. All processors can read an information from some cell (several processors can read an information from some cell simultaneously).

The parallel program is executed in several steps. During each step we execute the parallel version of the increment operation. Executing the parallel version of the increment operation goes as follows:

  1. Each processor independently of the other ones chooses some memory cell. Let's say that processor i has chosen a cell with number c__i (1 ≤ c__i ≤ n).
  2. All processors simultaneously execute operation a__i = a__i + a__c__i.

Help Polycarpus come up with the parallel program model that is executed in exactly k steps. Calculate the operations that need to be executed. Note that after k steps for all i's value a__i must be equal n - i.

Polycarpus 有一台拥有 nn 个处理器的计算机,该计算机还拥有 nn 个内存单元。我们将处理器编号为 11 至 nn 的整数,内存单元也依次编号为 11 至 nn 的整数。

Polycarpus 需要设计一个并行程序模型:对每个内存单元编号 ii,该程序必须向该单元写入值 n−in - i。换言之,对每个单元,需计算其到第 nn 个单元的距离。

记第 ii 个内存单元中存储的值为 aia_i。初始时,ai=1a_i = 1(其中 1≤i<n1 \leq i < n),且 an=0a_n = 0。我们规定:仅处理器 ii 可向第 ii 个内存单元写入值;但所有处理器均可读取任意内存单元中的信息(多个处理器可同时读取同一内存单元)。

该并行程序分若干步执行。每一步中,我们执行一次“增量操作”的并行版本。该并行增量操作的执行过程如下:

  1. 每个处理器独立于其他处理器,选择某个内存单元。设处理器 ii 选择了编号为 cic_i 的内存单元(其中 1≤ci≤n1 \leq c_i \leq n)。
  2. 所有处理器同时执行赋值操作:ai=ai+acia_i = a_i + a_{c_i}。

请帮助 Polycarpus 设计一个恰好执行 kk 步的并行程序模型,并计算出每一步中各处理器所需执行的操作。注意:经过 kk 步后,对所有 ii,必须满足 ai=n−ia_i = n - i。

输入格式

The first line contains two space-separated integers n and k (1 ≤ n ≤ 104, 1 ≤ k ≤ 20).

It is guaranteed that at the given n and k the required sequence of operations exists.

第一行包含两个以空格分隔的整数 nn 和 kk(1 ≤ n ≤ 1041 \leq n \leq 10^4,1 ≤ k ≤ 201 \leq k \leq 20)。

保证在给定的 nn 和 kk 下,所要求的操作序列存在。

输出格式

Print exactly n·k integers in k lines. In the first line print numbers _c_1, _c_2, ..., c__n (1 ≤ c__i ≤ n) for the first increment operation. In the second line print the numbers for the second increment operation. In the k-th line print the numbers for the k-th increment operation.

As a result of the printed operations for any i value a__i must equal n - i.

恰好打印 n⋅kn \cdot k 个整数,分 kk 行输出。第一行输出第一次增量操作所用的数字 c1, c2, …, cnc_1,\,c_2,\,\dots,\,c_n(其中 1≤ci≤n1 \leq c_i \leq n);第二行输出第二次增量操作所用的数字;……;第 kk 行输出第 kk 次增量操作所用的数字。

经过上述所打印的操作后,对任意 ii,必须满足 ai=n−ia_i = n - i。

输入输出样例

  • 输入#1

    1 1

    输出#1

    1
  • 输入#2

    3 2

    输出#2

    2 3 3
    3 3 3

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

首页