QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#583371#9378. Strange BinarywuliangyeAC ✓11ms3688kbC++23992b2024-09-22 19:42:102024-09-22 19:42:12

Judging History

你现在查看的是最新测评结果

  • [2024-09-22 19:42:12]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:3688kb
  • [2024-09-22 19:42:10]
  • 提交

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