1192: [HNOI2006] Ghost Millet Money bag time limit:10 Sec Memory limit:162 MB
submit:3223 solved:2333
Descriptio
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?
Input
Contains an integer that represents the total number of gold coins existing in the ghost millet m. Among them, 1≤m≤1000000000.
Output
Only an integer h, indicating the number of pockets of money
Sample Input
3Sample Output
2
/*It is said that this is the most correct solution, the binary all the purse can be regarded as a take or not to take the case. Then these money bags can be taken or not taken as 0 or 1, that is, to use some numbers to denote a range of all the numbers at the same time this is very binary (take or not). So we set the amount of money in the purse to 2^n. I don't understand the rationale for this idea .... */#include<cstdio>intMain () {intm,tot=0, ans[ -]; scanf ("%d",&m); for(;m>>1; m>>=1) ans[++tot]= (m>>1) + (m&1); printf ("%d\n", tot+1);}/*so it's a good way to do this mess, simple and easy to understand can pass! Actually, it's not as complicated as we thought it would be. If m=12, then we need to get the combination scheme (1 2 3 4 ...). 12) We can divide them into two parts (1 2 ...). 6) (7 8 ... 12) The left side of the L to the right of R it is easy to know that each scheme of R can be divided into two parts (1 2 3) by the combination of (12/2) + left side (4 5 6) Similarly, when M is odd, it is obvious to change (M/2) to (m/2+1)*/#include<iostream>#include<cstdio>using namespacestd;Long LongN,m,ans,tot;inta[1000001];//the array records the amount of money in each bag, ready to export! HahaintMain () {scanf ("%d",&N); while(n/2!=0) {tot++; if(n%2==0) a[tot]=n/2; if(n%2==1) a[tot]=n/2+1; N/=2; } printf ("%d\n", tot+1); return 0;}
If the heart is sunny, no words sorrow
bzoj1992 Ghost Millet Money Bag (two-point mess)