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 }
浙公网安备 33010602011771号