40分求助!(为什么公布成绩时是30分,洛谷上测却是40分???)

P7071 [CSP-J2020] 优秀的拆分

```cpp #include<bits/stdc++.h> using namespace std; int x,n; int main() { scanf("%d",&n); if(n%2==1){ printf("-1"); return 0; } for(int i=2;i<=100;i=i+2){ x=pow(2,26); while(x>1){ if(n-x>=0){ n-=x; printf("%d",x ); } x=x/2; } } } ``` **我的方法请您过目**
by Bill_Cipher_137 @ 2020-11-22 14:58:19


@[lcyxds](/user/124314) 我只是提个意见...那我的正解@[justinjia](/user/373226) 也可以看一下吧 ```cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,i=0; ll q[10009]; int main(){ cin>>n; if(n%2==1){ cout<<-1; return 0; } while(n){ q[++i]=n&-n; n-=n&(-n); } for(int j=i;j>=1;j--){ cout<<q[j]; if(j!=1)cout<<' '; } return 0; } ```
by lihaochen_harold @ 2020-11-23 22:19:11


~~@[faswasqas_fff](/user/368171) 不缩进。。。~~
by justinjia @ 2020-11-25 17:08:33


@[lihaochen_harold](/user/284855) `typedef long long ll;`啥意思? ~~(这验证码咋弄出来的,上来就wa。。。)~~
by justinjia @ 2020-11-25 17:37:53


@[justinjia](/user/373226) typedef long long ll;是指将long long 类重命名为ll; 在重新定义后,再写 ```cpp long long a; ``` 时可以写为 ``` ll a; ``` (方便偷懒,建议写缺省源里) 不过这个代码里没用到,可以忽略这一行
by lihaochen_harold @ 2020-11-25 21:30:05


@[lihaochen_harold](/user/284855) ```typedef long long ll;```是不是相当于```#define/*我很少用这个*/ ll long long```?
by justinjia @ 2020-11-26 16:44:38


@[justinjia](/user/373226) 啊对啊
by lihaochen_harold @ 2020-11-26 19:20:42


```c++ #include <iostream> int main() { int p; std::cin >> p; if(p % 2) { printf("-1");return 0; } for(int i = 8388608; i > 1; i /= 2) if(p >= i) { p -= i; printf("%d ", i); } } ```
by hyk2019 @ 2020-12-22 20:07:56


@[hyk2019](/user/276246) 简化版 ```c++ #include<iostream> int main(){int p;std::cin>>p;if(p%2)printf("-1");else for(int i=8388608;i>1;i/=2)if(p>=i){p-=i;printf("%d ",i);}} ```
by hyk2019 @ 2020-12-22 20:10:27


上一页 |