QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 512 MB 満点: 100

#1422. 平均值

統計

寻找一个步骤序列(如果存在),使得任意实数数组 $a_1, a_2, \dots, a_n$ 的所有元素最终相等。步骤定义如下:

  • 选择 $k$ 个不同的下标 $b_1, b_2, \dots, b_k$ ($1 \le b_i \le n$),并将 $a_{b_1}, a_{b_2}, \dots, a_{b_k}$ 的值同时修改为它们的算术平均值(即 $\frac{1}{k}(a_{b_1} + a_{b_2} + \dots + a_{b_k})$)。

输入格式

仅一行,包含两个整数 $n$ 和 $k$ ($2 \le k \le n \le 1000$; $n$ 能被 $k$ 整除)。

输出格式

如果不存在所需的步骤序列,输出单个整数 $-1$。

否则,输出序列中的步骤数 $t$ ($1 \le kt \le 10^6$),随后输出 $t$ 个步骤描述。每个步骤描述必须包含 $k$ 个不同的整数 $b_1, b_2, \dots, b_k$ ($1 \le b_i \le n$)。

可以证明,如果存在有效的步骤序列,则一定存在满足 $kt \le 10^6$ 的序列。

样例

输入格式 1

4 2

输出格式 1

4
1 2
3 4
1 3
2 4

输入格式 2

6 3

输出格式 2

-1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.