codeforces1348 D. Phoenix and Science

D. Phoenix and Science

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 m2m2each. 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!

Input

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

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

Output

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.

Example

input

Copy

3
9
11
2

output

Copy

3
1 0 2 
3
1 1 2
1
0 

Note

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.

题意:

现在有一个重量为1的细菌,细菌每天晚上重量都会增加1,1个重量为1的细菌可以分裂为2个重量为0.5的细菌,问最短几天总重量可以达到 n,输出每天的细菌分裂数。

思路:

要注意到细菌分裂不会导致细菌重量增加,只是每天晚上才会增重。设第 i 天的细菌数是 a[i],最少天数为 k 天,那么总重量就是1 + a[1] + a[2] + a[3] + ...... + a[k],a[1] .....a[k]也就是 2,4,8,16……

先找出最大的 k 使得 2^1 + 2^2 + ..... + 2^k <= n,剩余的数和这些2的幂排个序,每天需要分裂的细菌数就是相邻两天的细菌差

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
const double PI = acos(-1.0);
const int N = 520;

int main()
{
    int t, n;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        vector<int>ans;
        for(int i = 1; i <= n; i <<= 1)
        {
            ans.push_back(i);
            n -= i;
        }
        if(n)
        {
            ans.push_back(n);
        }
        sort(ans.begin(), ans.end());
        int siz = ans.size() - 1;
        cout<<siz<<'\n';
        for(int i = 0; i < siz; ++i)
        {
            cout<<ans[i + 1] - ans[i];
            if(i < siz - 1)
                cout<<' ';
        }
        cout<<'\n';
        ans.clear();
    }
    return 0;
}

 

全部评论

相关推荐

03-12 15:35
嘉应学院 Python
快说谢谢牛牛精灵:说不定就是下一个寒武纪!
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
4491次浏览 39人参与
# 你的实习产出是真实的还是包装的? #
1041次浏览 27人参与
# MiniMax求职进展汇总 #
22776次浏览 292人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
6867次浏览 36人参与
# 简历第一个项目做什么 #
31234次浏览 312人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186322次浏览 1114人参与
# 巨人网络春招 #
11132次浏览 221人参与
# 面试紧张时你会有什么表现? #
30313次浏览 188人参与
# 简历中的项目经历要怎么写? #
309332次浏览 4147人参与
# 网易游戏笔试 #
6300次浏览 83人参与
# 职能管理面试记录 #
10676次浏览 59人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
6809次浏览 154人参与
# 从哪些方向判断这个offer值不值得去? #
56693次浏览 357人参与
# 腾讯音乐求职进展汇总 #
160385次浏览 1105人参与
# 小红书求职进展汇总 #
226831次浏览 1356人参与
# AI时代,哪些岗位最容易被淘汰 #
62295次浏览 723人参与
# 你怎么看待AI面试 #
179221次浏览 1160人参与
# 正在春招的你,也参与了去年秋招吗? #
362456次浏览 2631人参与
# 你的房租占工资的比例是多少? #
92119次浏览 896人参与
# 机械求职避坑tips #
94392次浏览 567人参与
# 校招笔试 #
465886次浏览 2948人参与
# 面试官最爱问的 AI 问题是...... #
27023次浏览 833人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务