ZOJ 3870 Team Formation (Mathematics)

Source: Internet
Author: User

ZOJ 3870 Team Formation (Mathematics)

 

Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB

 

For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team fromNStudents of his university.

Edward knows the skill level of each student. He has found that if two students with skill levelAAndBForm a team, the skill level of the team will beABytesB, Where each means bitwise exclusive or. A team will play well if and only if the skill level of the team is greater than the skill level of each team member (I. e.ABytesB> Max {A,B}).

Edward wants to form a team that will play well in the contest. Please tell him the possible number of such teams. Two teams are considered different if there is at least one different team member.

Input

There are multiple test cases. The first line of input contains an integerTIndicating the number of test cases. For each test case:

The first line contains an integerN(2 <=N<= 100000), which indicates the number of student. The next line containsNPositive integers separated by spaces.IthInteger denotes the skill levelIthStudent. Every integer will not exceed 109.

Output

For each case, print the answer in one line.

Sample Input
231 2 351 2 3 4 5
Sample Output
16

Question: Find a combination of sequence a or sequence B> max (a, B). There is no sequence that is very

 

Idea: sort the values first, and then sort the values with a binary number. If the value is greater than or equal to the value of a binary number, it must be that the position of 0 in the binary number is 1, and this bit is the highest bit of the other.

 

 

#include
 
  #include
  
   #include
   
    #include#include
    
     #include
     
      #include
      
       #include
       
        #include
        
         #include
         #define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e-8#define fre(i,a,b) for(i = a; i 
          
           = a;i--)#define mem(t, v) memset ((t) , v, sizeof(t))#define ssf(n) scanf("%s", n)#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define bug pf("Hi\n")using namespace std;#define INF 0x3f3f3f3f#define N 100005int vis[N],a[N];int n,ans;inline void call(int x){ int i=0; while(x) { i++; x>>=1; } vis[i-1]++;}inline void solve(int x){ int i; fre(i,0,31) if(!(x&(1<
           
            

 

 

 

 

 

 

 

Related Article

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.