竞赛
考级
滑稽 . . . . . . . . . . . . . . . . . . . . . . . . 不会真的有人去提交了吧(小声)
#include <bits/stdc++.h> using namespace std; long long n,ans,j = 1; int main(){ cin>>n; if(n%2==1){ ans = -1; cout<<ans; return 0; } while(pow(2,j)<10000000){ if(pow(2,j)==n){ ans = n; cout<<ans; return 0; } j++; } while(n>=2){ int tmp = 1; while(pow(2,tmp)<=n){ tmp+=1; } ans = pow(2,(tmp-1)); n-=ans; cout<<ans<<" "; } return 0; }
这不就二进制吗(恼 太水了吧(
题目:A36 不是我不想注释,主要是我之前写的代码现在自己看不懂了(悲),有人能读懂吗? 望大佬能讲解下
为啥答案输入256会输出256? 我的代码错哪了? 有人能帮解答一下吗?
为什么第一个例子我输出-1还错了
#include <bits/stdc++.h> using namespace std; int main(){ int a; cin>>a; int y=1; if(a%2!=0){ cout<<"-1"; } else{ while(y<a){ y=2*y; } while(a>1){ while(y>a){ y=y/2; } a=a-y; cout<<y<<" "; } } }
炸了,AI的解释看不懂 有哪位大佬能帮忙看一下吗,测试点就错了#9、10、11、13
根本不会
这里面竟然有log2这个函数(求这个数是2的几次方 Dev-C++里没有 注意转int
没思路,悲!
二进制也不会啊(恼
脑子死了
#include <bits/stdc++.h> using namespace std; int n,dp[25],num = 4; int main() { cin >> n; dp[1] = 2; for(int i = 2;i <= 23;i ++) { dp[i] = dp[i - 1] + num; num >>= 1; } bool flag = 0,nu = 0; for(int i = 1;i <= 23;i ++) { if(dp[i] == n) { nu = i; flag = 1; } } if(flag) { for(int i = nu + 1;i >= 1;i --) { cout << (1 << i) << " "; } } else cout << -1; return 0; }
2可以吗
提交答案之后,这里将显示提交结果~