60pts求助!

P7071 [CSP-J2020] 优秀的拆分

@[holdyhao_Genius](/user/494699) hack: in: ``` 12 ``` your output: ``` 8 2 2 ``` answer: ``` 8 4 ```
by ran_qwq @ 2023-01-06 19:18:51


@[Lovely_Ran](/user/743048) 这个我知道呀。
by 卷王 @ 2023-01-06 19:22:57


@[holdyhao_Genius](/user/494699) 每一步都考虑最优决策,你的循环是反着来的,因此寻找到一个最大值就立马停止。 ``` #include <bits/stdc++.h> using namespace std; int n, now, cnt = 0; int a[10000001]; int main() { cin >> n; if(n % 2 == 1) { cout << -1; return 0; } now = log2(n); while(n) { n -= (1 << now); a[++cnt] = (1 << now); if(n == 0) { for(int i = 1; i <= cnt; i++) cout << a[i] << " "; return 0; } for(int i = now - 1; i >= 1; i--) if((1 << i) <= n){ now = i; break;//更改 } } return 0; } ```
by Dream_Creator @ 2023-01-06 19:24:28


@[艾因斯坦](/user/529722) 谢谢
by 卷王 @ 2023-01-06 20:22:49


|