QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#12305. 排列组合游戏

Statistiques

终于,著名的间谍和特工詹姆斯·邦德成功找到了他目前的宿敌——Zlo 博士。他们在 Permutasino 赌场的轮盘赌桌前相遇,现在 007 试图猜出他那邪恶敌人的最新邪恶计划。

轮盘赌桌包含 $n!$ 个格子,分别对应 $1$ 到 $n$ 之间所有可能的排列。这种轮盘赌的下注过程相当不同寻常:玩家最多可以对其中的某些格子进行 $n$ 次下注。每一注都是一个非负数 $b_\pi$,其中 $\pi$ 表示该注对应的排列。所有下注金额之和应等于 $1$。

下注完成后,轮盘机制会根据 $b_\pi$ 定义的分布随机选择一个排列。形式上,如果对排列 $\pi$ 进行了下注,则以概率 $b_\pi$ 选择排列 $\pi$,否则以概率 $0$ 选择。

为了在这场智力博弈中击败 Zlo 博士并说服他透露邪恶计划,007 必须进行下注,使得所得排列的期望值向量为 $(x_1, x_2, \dots, x_n)$。长度为 $n$ 的随机排列的期望值定义为一个长度为 $n$ 的向量,其中第 $i$ 个元素是随机排列中第 $i$ 个位置上的值的期望值。

请帮助詹姆斯·邦德进行适当的下注,或者确定这是不可能的,这样他这次就不得不通过其他手段(比如射杀所有人并炸毁沿途的每一座建筑)来拯救世界。

输入格式

第一行包含一个整数 $n$,表示轮盘赌桌上出现的排列长度 ($1 \le n \le 500$)。

第二行包含 $n$ 个整数 $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$),表示所得排列的期望值向量。

输出格式

如果无法获得向量 $(x_1, x_2, \dots, x_n)$ 作为游戏结果的期望值,请输出 $-1$。

否则,在第一行输出 $k$ ($1 \le k \le n$),表示詹姆斯·邦德进行的下注次数。

在接下来的 $k$ 行中,每行输出下注金额 $b_{\pi_i}$ ($0 \le b_{\pi_i} \le 1$) 和 $n$ 个整数 $\pi_{i,1}, \pi_{i,2}, \dots, \pi_{i,n}$ ($1 \le \pi_{i,j} \le n$,且对于所有 $1 \le j \le n$,$\pi_{i,j}$ 互不相同),用以定义对应的排列 $\pi_i$。

$b_{\pi_1} + b_{\pi_2} + \dots + b_{\pi_k}$ 的和应等于 $1$,绝对误差不超过 $10^{-6}$。对于所有 $1 \le j \le n$,值 $|b_{\pi_1} \pi_{1,j} + b_{\pi_2} \pi_{2,j} + \dots + b_{\pi_k} \pi_{k,j} - x_j|$ 的最大值不应超过 $10^{-2}$。所有验证这些事实的计算都将使用双精度浮点数据类型执行。

如果存在多种可能的答案,输出其中任意一个即可。

样例

输入 1

4
2 2 3 3

输出 1

3
0.5000000000 1 2 3 4
0.1666666667 1 4 3 2
0.3333333333 4 1 3 2

输入 2

2
1 1

输出 2

-1

说明

在第一个样例中,所得排列的期望值为:

$$\left( \frac{1}{2} \cdot 1 + \frac{1}{6} \cdot 1 + \frac{1}{3} \cdot 4, \frac{1}{2} \cdot 2 + \frac{1}{6} \cdot 4 + \frac{1}{3} \cdot 1, \frac{1}{2} \cdot 3 + \frac{1}{6} \cdot 3 + \frac{1}{3} \cdot 3, \frac{1}{2} \cdot 4 + \frac{1}{6} \cdot 2 + \frac{1}{3} \cdot 2 \right) = (2, 2, 3, 3)$$

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#519Editorial Open集训队作业 解题报告 by 刘家炜Qingyu2026-01-02 21:37:54 Download
#241EditorialOpenNew Editorial for Problem #12305jiangly2025-12-13 00:26:52View

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.