QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#583371 | #9378. Strange Binary | wuliangye | AC ✓ | 11ms | 3688kb | C++23 | 992b | 2024-09-22 19:42:10 | 2024-09-22 19:42:12 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 32;
int n;
ll a[N]; //二进制拆分
void solve(ll );
int main(){
cin >> n;
while(n--){
ll x;
cin >> x;
if(x % 4 == 0){ //根据题意, 4 的倍数不行
cout << "NO" << endl;
continue;
}
else{
solve(x);
}
}
return 0;
}
void solve(ll x){
cout << "YES" << endl;
memset(a, 0, sizeof(a)); //更新
int cnt = 31; //计算到 2 的 31 位次
int t = 0; //输出个数
while(cnt >= 0){ //二进制拆分
a[31 - cnt] = x % 2;
x /= 2;
cnt--;
}
if(a[0] == 0){ //偶数
cout << 0 << ' ';
t++;
}
for(int i = (a[0] == 0 ? 1 : 0); i < 31; i++){
if(a[i + 1] == 0){
cout << - 1 << ' ';
t++;
}
else{
cout << 1 << ' ';
t++;
}
if(t == 8){
t = 0;
cout << endl;
}
}
cout << 1 << endl; //最后一个数字必须为 1
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
3 0 3 5
output:
NO YES 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 YES -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1
result:
ok Accepted! (3 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
2 0 1073741823
output:
NO YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 1
result:
ok Accepted! (2 test cases)
Test #3:
score: 0
Accepted
time: 11ms
memory: 3688kb
input:
10000 324097321 555675086 304655177 991244276 9980291 383616352 1071036550 795625380 682098056 68370721 969101726 685975156 973896269 354857775 196188000 606494155 754416123 467588829 495704303 558090120 618002000 491488050 741575237 9937018 10028830 140094825 652839595 357724903 516690123 817724271...
output:
YES -1 -1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 -1 -1 1 YES 0 1 1 -1 -1 1 1 1 -1 1 1 -1 1 1 1 -1 1 1 1 1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 -1 1 YES -1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 1 -1 -1 -1 1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1 -1 1 NO YES 1 -1 -1 -1 -1 -1 1 1 -1 -1...
result:
ok Accepted! (10000 test cases)
Extra Test:
score: 0
Extra Test Passed