80分,最后4个测试点wa掉了,求调

P7071 [CSP-J2020] 优秀的拆分

```cpp #include<bits/stdc++.h> using namespace std; int n; int main(){ cin>>n; if(n%2==1){ cout<<"-1"; } else{ while(n){ if(n==0){ break; } int a=1; while(n){ if(pow(2,a+1)>n){ break; } a++; } n-=pow(2,a); int x=pow(2,a); if(x%2==0)//pow(2,a)是否为2的倍数 cout<<x<<" "; } } return 0; } ``` 加个判断pow(2,a)是否为2的倍数的条件就行了
by zxy2580583102 @ 2023-07-19 09:14:07


哪个题。
by cwxclys @ 2023-07-19 10:06:32


P7071 [CSP-J2020] 优秀的拆分?
by cwxclys @ 2023-07-19 10:07:33


@[cwxclys](/user/949356) 是的
by zxy2580583102 @ 2023-07-19 17:12:12


@[zxy2580583102](/user/754725) 哦哦
by cwxclys @ 2023-07-19 20:09:43


pow()这个函数,没有定义呀
by yanghaoyu123 @ 2023-07-28 11:56:41


你答案应该改成int类型吧
by JesseDai @ 2023-08-16 14:47:34


```c #include<bits/stdc++.h> using namespace std; int n; int main(){ cin>>n; if(n%2==1){ cout<<"-1"; } else{ while(n){ if(n==0){ break; } int a=1; while(n){ if(pow(2,a+1)>n){ break; } a++; } n-=pow(2,a); cout<<(int)pow(2,a)<<" "; } } return 0; } ```
by JesseDai @ 2023-08-16 14:58:36


```cpp #include <algorithm> #include <stdio.h> #include <string.h> #include <math.h> int cnt, ans[100]; int main(){ // freopen("live.in", "r", stdin); // freopen("live.out", "w", stdout); long long n; scanf("%lld", &n); if(n % 2){ printf("%d ", -1); return 0; } while(!(n == 0)){ ans[cnt++] = n % 2; n /= 2; } for(int j = 1, i = cnt; i >= 0; i--, j++){ if(ans[i]) printf("%d ", (int)pow(2, i)); } return 0; } ```
by Windows12 @ 2023-08-20 14:58:14


|