P2320 [HNOI2006]鬼谷子的钱袋

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 
 5 int n;
 6 int tot;
 7 int a[100010];
 8 
 9 int main()
10 {
11     cin >> n;
12     while (n)
13     {
14         if (n & 1) a[++tot] = (n >> 1) + 1;
15         else a[++tot] = n >> 1;
16         n >>= 1;
17     }
18     sort(a + 1, a + tot + 1);
19     cout << tot << endl;
20     for (int i = 1; i <= tot; i++)
21         cout << a[i] << " ";
22     return 0;
23 }
View Code

 

posted on 2019-10-14 17:50  thjkhdf12  阅读(153)  评论(0)    收藏  举报