题解
首先判断输入数字是否在[1,1024]区间内,不在区间内直接输出-1.
1-1024 使用32个unsigned int 表示,每个unsigned int 有32位,表示32个数字的状态。
定义 vector<unsigned int> v(32)
其中 v[0] 表示 1-32,v[1] 表示 33-64,...
假设输入数据为a,b
则 a 在 v[(a-1)/32]中表示,表示a的可以直接用第 a%32位。
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
if (!(a >= 1 && a <= 1024) || !(b >= 1 && b <= 1024)) {
cout << -1 << endl;
return 0;
}
vector<unsigned int> v(32);
int x = (a - 1) / 32, y = a % 32;
v[x] = v[x] | (1 << y);
x = (b - 1) / 32, y = b % 32;
if (v[x] & (1 << y)) cout << 1 << endl;
else cout << 0 << endl;
}