ZOJ 3870 mathematical thinking

Source: Internet
Author: User

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 );
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.