这题让我发现二进制运算符对格式的严格
比如
if (now & (1LL << j))
取得不是一位数,而是最高位为1其他位均为0的数
还有
(ans ^ a[i]) > ans
记得打括号!
#include <cstdio>
const int N = 60;
int n;
long long now, ans;
long long a[N];
//a数组为基
int main()
{
scanf ("%d", &n);
for (int i = 1; i <= n; ++i)
{
scanf ("%lld", &now);
for (int j = N; j >= 0; --j)
if (now & (1LL << j))
{
if (a[j] == 0)
{
a[j] = now;
break;
}
else
now ^= a[j];
}
}
for (int i = N; i >= 0; --i)
if ((ans ^ a[i]) > ans)
ans ^= a[i];
printf ("%lld
", ans);
return 0;
}