Zoj 3870 Team Formation bit operation
// Give n the number, and find the number of two teams with an exclusive or greater value than their own
// For the highest bit of a small number in a large number, this bit is 0
// The two numbers are larger than the two ones.
// Otherwise, this number is smaller than the big one.
# Include
# Include
# Include
# Include
Using namespace std;
Const int maxn = 100010;
Long map [40];
Int a [maxn];
Long solve (int m)
{
Int pos = 0;
Long ans = 0;
While (m> 1)
{
If (m % 2) = 0) ans + = map [pos];
M/= 2;
Pos ++;
}
Map [pos] ++;
Return ans;
}
Int main ()
{
Int n;
Int T;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
Memset (map, 0, sizeof (map ));
Long ans = 0;
For (int I = 1; I <= n; I ++)
Scanf ("% d", & a [I]);
Sort (a + 1, a + 1 + n );
For (int I = 1; I <= n; I ++)
Ans + = solve (a [I]);
Printf ("% lld \ n", ans );
}
Return 0;
}