CF1348D.Phoenix and Science

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria.

Initially, on day 11, there is one bacterium with mass 11.

Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass mm splits, it becomes two bacteria of mass m2\frac{m}{2} each. For example, a bacterium of mass 33 can split into two bacteria of mass 1.51.5.

Also, every night, the mass of every bacteria will increase by one.

Phoenix is wondering if it is possible for the total mass of all the bacteria to be exactly nn. If it is possible, he is interested in the way to obtain that mass using the minimum possible number of nights. Help him become the best scientist!

凤凰决定成为一名科学家!他目前正在研究细菌的生长。

初始时,在第 11 天,有一个质量为 11 的细菌。

每天,一些细菌会分裂(可能为零个,也可能全部分裂)。当一个质量为 mm 的细菌分裂时,它会变成两个质量均为 m2\frac{m}{2} 的细菌。例如,一个质量为 33 的细菌可以分裂成两个质量均为 1.51.5 的细菌。

此外,每晚,每个细菌的质量都会增加 11。

凤凰想知道:是否有可能使所有细菌的总质量恰好等于 nn?如果可能,他希望用最少的夜晚数来达到该总质量。请帮助他成为最优秀的科学家!

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains an integer nn (2≤n≤1092 \le n \le 10^9) — the sum of bacteria masses that Phoenix is interested in.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤1092 \le n \le 10^9),表示 Phoenix 所关注的细菌总质量。

输出格式

For each test case, if there is no way for the bacteria to exactly achieve total mass nn, print -1. Otherwise, print two lines.

The first line should contain an integer dd — the minimum number of nights needed.

The next line should contain dd integers, with the ii-th integer representing the number of bacteria that should split on the ii-th day.

If there are multiple solutions, print any.

对于每个测试用例,如果细菌无法恰好达到总质量 nn,则输出 -1。否则,输出两行。

第一行应包含一个整数 dd —— 所需的最少天数。

下一行应包含 dd 个整数,其中第 ii 个整数表示第 ii 天应分裂的细菌数量。

如果有多种解法,输出任意一种即可。

输入输出样例

  • 输入#1

    3
    9
    11
    2

    输出#1

    3
    1 0 2 
    3
    1 1 2
    1
    0

说明/提示

In the first test case, the following process results in bacteria with total mass 99:

  • Day 11: The bacterium with mass 11 splits. There are now two bacteria with mass 0.50.5 each.
  • Night 11: All bacteria's mass increases by one. There are now two bacteria with mass 1.51.5.
  • Day 22: None split.
  • Night 22: There are now two bacteria with mass 2.52.5.
  • Day 33: Both bacteria split. There are now four bacteria with mass 1.251.25.
  • Night 33: There are now four bacteria with mass 2.252.25.

The total mass is 2.25+2.25+2.25+2.25=92.25+2.25+2.25+2.25=9. It can be proved that 33 is the minimum number of nights needed. There are also other ways to obtain total mass 9 in 3 nights.

$ $

In the second test case, the following process results in bacteria with total mass 1111:

  • Day 11: The bacterium with mass 11 splits. There are now two bacteria with mass 0.50.5.
  • Night 11: There are now two bacteria with mass 1.51.5.
  • Day 22: One bacterium splits. There are now three bacteria with masses 0.750.75, 0.750.75, and 1.51.5.
  • Night 22: There are now three bacteria with masses 1.751.75, 1.751.75, and 2.52.5.
  • Day 33: The bacteria with mass 1.751.75 and the bacteria with mass 2.52.5 split. There are now five bacteria with masses 0.8750.875, 0.8750.875, 1.251.25, 1.251.25, and 1.751.75.
  • Night 33: There are now five bacteria with masses 1.8751.875, 1.8751.875, 2.252.25, 2.252.25, and 2.752.75.

The total mass is 1.875+1.875+2.25+2.25+2.75=111.875+1.875+2.25+2.25+2.75=11. It can be proved that 33 is the minimum number of nights needed. There are also other ways to obtain total mass 11 in 3 nights.

$ $

In the third test case, the bacterium does not split on day 11, and then grows to mass 22 during night 11.

在第一个测试用例中,以下过程可得到总质量为 99 的细菌:

  • 第 11 天:质量为 11 的细菌分裂。此时共有两个质量均为 0.50.5 的细菌。
  • 第 11 夜:所有细菌的质量均增加 11。此时共有两个质量均为 1.51.5 的细菌。
  • 第 22 天:没有细菌分裂。
  • 第 22 夜:此时共有两个质量均为 2.52.5 的细菌。
  • 第 33 天:两个细菌均分裂。此时共有四个质量均为 1.251.25 的细菌。
  • 第 33 夜:此时共有四个质量均为 2.252.25 的细菌。

总质量为 2.25+2.25+2.25+2.25=92.25+2.25+2.25+2.25=9。可以证明,33 是所需夜晚数的最小值。此外,也存在其他方式在 33 个夜晚内达到总质量 99。

$ $

在第二个测试用例中,以下过程可得到总质量为 1111 的细菌:

  • 第 11 天:质量为 11 的细菌分裂。此时共有两个质量均为 0.50.5 的细菌。
  • 第 11 夜:此时共有两个质量均为 1.51.5 的细菌。
  • 第 22 天:其中一个细菌分裂。此时共有三个细菌,质量分别为 0.750.75、0.750.75 和 1.51.5。
  • 第 22 夜:此时共有三个细菌,质量分别为 1.751.75、1.751.75 和 2.52.5。
  • 第 33 天:质量为 1.751.75 的细菌和质量为 2.52.5 的细菌分裂。此时共有五个细菌,质量分别为 0.8750.875、0.8750.875、1.251.25、1.251.25 和 1.751.75。
  • 第 33 夜:此时共有五个细菌,质量分别为 1.8751.875、1.8751.875、2.252.25、2.252.25 和 2.752.75。

总质量为 1.875+1.875+2.25+2.25+2.75=111.875+1.875+2.25+2.25+2.75=11。可以证明,33 是所需夜晚数的最小值。此外,也存在其他方式在 33 个夜晚内达到总质量 1111。

$ $

在第三个测试用例中,该细菌在第 11 天不发生分裂,并在第 11 夜增长至质量 22。

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

首页