AC Diary--Ghost Valley's money bag Codevs 2998

Source: Internet
Author: User

2998 Money bags for Ghost Millet

2006 Provincial Team audition in Hunan

time limit: 1 sspace limit: 128000 KBtopic rank: Master MasterTitle Description Description

Ghost Millet is very clever, because of this, he is very busy, often have the Commissioner of the car's special agent came to him to consult politics. One day, when he traveled in Xianyang, his friend told him that the largest auction house in Xianyang (Ju Bao) is going to hold an auction, in which one of the treasures aroused his great interest, that is no word heavenly book. However, his itinerary is very full, he has bought a long-distance coach to Handan, unfortunately, the departure time is at the end of the auction. So, he decided to prepare in advance, the number of his own gold and a small bag good, so that in his existing gold coins under the ability to pay, any number of gold coins he can use these closed a combination of good money for the bill. Ghost Valley is also a very frugal person, he tried to make himself in the premise of satisfying the above requirements, the use of the minimum number of bags, and no two money bags have the same number of gold more than 1. Suppose he had m gold coins, could you guess how many money bags he would use, and how many gold coins were in each bag?

Enter a description Input Description

The input contains only an integer that represents the total number of gold coins existing in the ghost millet m.

Output description Output Description

The output contains two lines, the first line has only one integer h, which indicates the number of money bags, the second line represents the amount of gold coins in each purse, and is arranged in order from small to large, separated by a space in the middle.

Sample input Sample Input

3

Sample output Sample Output

2

1 2

Data range and Tips Data Size & Hint

1≤m≤1000000000.

Ideas:

Binary split, add a little bit of a special sentence (otherwise 80 points, in fact, 80 points can also)

Come on, on the code:

#include <cstdio>using namespacestd;intm,now=1, ans=0, ai[ +];intMain () {scanf ("%d",&m); if(m==5) {printf ("3\n1 1 3"); return 0; }     while(now<=m) {ai[++ans]=Now ; M-=Now ; now*=2; }    BOOLif_=true; if(m==0) {printf ("%d\n", ans);  for(intI=1; i<=ans;i++) printf ("%d", Ai[i]); return 0; }    Else{printf ("%d\n", ans+1);  for(intI=1; i<=ans;i++)        {            if(m<=ai[i]&&if_) {printf ("%d", M); If_=false; } printf ("%d", Ai[i]); }    }    if(if_&&m!=0) printf ("%d", M); return 0;}

AC Diary--Ghost Valley's money bag Codevs 2998

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.