Luo Gu P2320 partition

Guiguzi very clever, because of this, he is very busy, often the princes of the car to come to get advice on current affairs commissioner.

One day, he traveled in Xianyang, when a friend told him an auction to be held in Xianyang largest auction house (Treasure firm), there is a treasure which caused him great interest, and that is Wordless Book.

But his itinerary is very full, long-distance horse he had bought a ticket to Handan, unfortunately the departure time is in the auction is about to end. So he decided to prepare in advance, you will own a good number of gold coins and a little money with a good bag, to his ability to pay under existing gold coins, any number of coins he can use a combination of these closed good money pay the bill.

Guiguzi also a very thrifty person, he tried to make his own purse on the premise of meeting the above requirements, with the minimum number, and there are no two identical pockets with gold number greater than 1. He assumed that there are m gold coins, you can guess how much he would use a purse, money and how many coins of each bagged it?

Input format
comprises an integer representing the conventional Guiguzi total number of coins m. Which, 1≤m ≤1000000000.

Output Format
two rows, a first row H integer, indicating the number of used purse

The second line indicates the number of coins of each purse is loaded, the output of small to large, space-separated

Sample Input Output
Input # 1 Copy
3
output copy # 1
2
1 2

Meaning of the questions: to give you a number to be divided into a number of individual and can not be duplicated other than 1, and meet the 1 ~ n-1 can be obtained by the number of points each, and can be divided into at least ask a few number of
ideas: brain-dong ... look at the large range of data ... outrageous violence enumeration (x) Search (x) dp (x) calculated that complexity can be had in O (log n) so that the partition was out out of the chestnuts such as to give you a 20 it can be divided into 1 to 10 and 11-20 and 1-10 in turn may be divided into sub-sequence down 1-5 and 6-10 we obtain when n> 2 can be divided into the n-1-n / 2 and n / 2 + 1 - n satisfy the partition idea

#include <iostream>

using namespace std;

int a[100005];

int main()
{

    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    int k=0;

    while(n)
    {
        a[++k]=(n+1)/2;
        n/=2;
    }

    cout << k << endl;

    for(int i=k;i>=1;i--)
        cout << a[i] << " ";

    cout << endl;

    return 0;
}
Published 54 original articles · won praise 0 · Views 1224

Guess you like

Origin blog.csdn.net/weixin_44144278/article/details/99618573