ZOJ 3870 mathematical thinking
Question: give you n numbers to find out how many numbers a is different or B is greater than max (a, B)
Question: First, we know that the method of an exclusive or operation is the same as 0, and the method is the same as 1. We can know that if we want to increase the number of BITs, it must be more than the same bits, second, we need to know that the nth power of 2 is equal to the n-1 power of 2 and the 1 power of 2 plus 1, that is, the maximum effect is greater than the sum of the low power, that is to say, if only a number is different from the maximum bits of other numbers, the value is equal to or greater than max (a, B );
Code:
# Include
# Include
# Include
Using namespace std;
Int value [100005];
Int main ()
{
Int T, mark [31], n, a [31];
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
For (int I = 1; I <= n; I ++)
{
Scanf ("% d", & value [I]);
}
Sort (value + 1, value + 1 + n );
Int sum = 0;
Memset (a, 0, sizeof ());
For (int I = 1; I <= n; I ++)
{
Memset (mark, 0, sizeof (mark ));
Int num = 0;
Sum + = (I-1 );
While (value [I])
{
Mark [num ++] = value [I] % 2;
Value [I]/= 2;
}
Int maxx;
For (int I = 0; I <num; I ++)
{
If (mark [I]) sum-= a [I], maxx = I;
}
A [maxx] ++;
}
Printf ("% d \ n", sum );
}
}