QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#593716 | #9378. Strange Binary | wjynb666 | AC ✓ | 15ms | 4096kb | C++11 | 1.5kb | 2024-09-27 15:38:11 | 2024-09-27 15:38:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define read_fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
// void solve(){
// int n;
// scanf("%d",&n);
// if(n % 4==0){
// printf("NO\n");
// return ;
// }
// vector<int> b(32,-2);
// for(int i=31;i>=0;i--){
// int cur=(n>>i)&1;
// if(!cur && b[i]==-2){
// b[i]=1;
// b[i-1]=-1;
// }else if(!cur && b[i]==-1){
// b[i-1]=-1;
// }else if(cur && b[i]==-2) {
// b[i]=1;
// }
// }
// printf("YES\n");
// for(int i=0;i<32;i++){
// printf("%d ",b[i]);
// if((i+1)%8==0) printf("\n");
// }
// }
void solve() {
int n;
scanf("%d", &n);
if (n % 4 == 0) {
printf("NO\n");
return;
}
vector<int> bit(32);
int m = 32;
for (int i = 0; i < m; ++i) {
bit[i] = n % 2; // 存储 n 的 原始bit位
n /= 2;
}
for (int i = 0; i < m; ++i) {
// 贪心替换 位置为0的地方
while (i + 1 < m && (bit[i] && !bit[i+1])) {
bit[i+1] = 1;
bit[i] = -1;
++i;
}
}
printf("YES\n");
for (int i = 0; i < m; ++i) {
printf("%d ", bit[i]);
if ((i + 1) % 8 == 0) {
printf("\n");
}
}
}
int main()
{
//read_fast;
int t;
cin>>t;
while(t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
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: 4096kb
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: 15ms
memory: 3780kb
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...
result:
ok Accepted! (10000 test cases)
Extra Test:
score: 0
Extra Test Passed