Skip to content

Commit

Permalink
线性基(用于解决异或和问题)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-XYS committed Mar 5, 2017
1 parent aae45b1 commit e567065
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Linear-Basis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <cstdio>

using namespace std;

int n, d[100000], b[32], bsize;

void linear_basis()
{
for (int i = 0; i < n; i++)
{
for (int j = 30; j >= 0 && d[i] != 0; j--)
{
if ((d[i] >> j) == 0) continue;
else if (b[j] != 0) d[i] ^= b[j];
else
{
b[j] = d[i];
bsize++;
break;
}
}
}
}

int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &d[i]);
}
linear_basis();
return 0;
}

0 comments on commit e567065

Please sign in to comment.