Zoj 3870 Team Formation bit operation

Source: Internet
Author: User

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















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.