UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#193677#3403. XOR就是ADDxuzhenming100349ms9016kbC++563b2023-10-14 11:25:212023-10-14 13:04:09

answer

#include<bits/stdc++.h>
using namespace std;
int a[1005],sz[1000005],b[1000005];
int  erjinzhi(int n)
{
	memset(a,0,sizeof(a));
	int i=0;
	while(n>0){
        a[i]=n%2;
        i++;
        n /= 2;
    }
    return i;
}
int main(){
	int n;
	cin>>n;
	for(int i=n-1;i>=0;i--){
		if(!b[i]){
		int l=erjinzhi(i);
		int x=1,sum=0;
		for(int j=0;j<l;j++){
			if(a[j]==0){
				sum=sum+x;
			}
			x*=2;
		}
		sz[sum]=i;
		sz[i]=sum;
		b[sum]=1;
		b[i]=1;
		}
	}
	for(int i=0;i<n;i++){
		cout<<sz[i]<<" ";
	}
	return 0;
}

/*10 0
*/

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

8

output:

7 6 5 4 3 2 1 0 

result:

ok ok n = 8

Test #2:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

9

output:

0 6 5 4 3 2 1 8 7 

result:

ok ok n = 9

Test #3:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

10

output:

1 0 5 4 3 2 9 8 7 6 

result:

ok ok n = 10

Test #4:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

19

output:

0 2 1 12 11 10 9 8 7 6 5 4 3 18 17 16 15 14 13 

result:

ok ok n = 19

Test #5:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

20

output:

3 2 1 0 11 10 9 8 7 6 5 4 19 18 17 16 15 14 13 12 

result:

ok ok n = 20

Test #6:

score: 10
Accepted
time: 0ms
memory: 1216kb

input:

999

output:

0 6 5 4 3 2 1 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 998 997 996 995 994 993 992 991 990...

result:

ok ok n = 999

Test #7:

score: 10
Accepted
time: 0ms
memory: 1220kb

input:

1000

output:

7 6 5 4 3 2 1 0 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 999 998 997 996 995 994 993 992 991 99...

result:

ok ok n = 1000

Test #8:

score: 10
Accepted
time: 123ms
memory: 9016kb

input:

1000000

output:

63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 3...

result:

ok ok n = 1000000

Test #9:

score: 10
Accepted
time: 14ms
memory: 2236kb

input:

131315

output:

0 2 1 12 11 10 9 8 7 6 5 4 3 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225...

result:

ok ok n = 131315

Test #10:

score: 10
Accepted
time: 212ms
memory: 8868kb

input:

979797

output:

0 2 1 4 3 10 9 8 7 6 5 20 19 18 17 16 15 14 13 12 11 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27...

result:

ok ok n = 979797

Extra Test:

score: 0
Extra Test Passed