Topic Links:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3870
Exercises
If X XOR Y>max (× X/y), then there will be a difference in the highest bit of x and Y (binary representation), and for the highest bit position of the highest bit of the number, the highest bit size should be 0 in the same position.
Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6typedefLong LongLL;7 Const intMAXN = 1e5 +Ten;8 9 intN;Ten One intARR[MAXN]; A //Cnt[i] Indicates how many of the highest-level I - intcnt[ +]; - the voidinit () { -memset (CNT,0,sizeof(CNT)); - } - + intMain () { - intTC; +scanf"%d", &TC); A while(tc--) { at init (); -scanf"%d", &n); - for(inti =0; i<n; i++) { -scanf"%d", &arr[i]); - for(intj = -; J >=0; j--) { - if((1<< j) &Arr[i]) { incnt[j]++; Break; - } to } + } -LL ans =0; the for(inti =0; i<n; i++) { * intJ; $ for(j = -; J >=0; j--) {Panax Notoginseng if((1<< j) &Arr[i]) { - Break; the } + } A for(J-=1; J >=0; j--) { the if(((1<< j) &arr[i]) = =0) { +Ans + =Cnt[j]; - } $ } $ } -printf"%lld\n", ans); - } the return 0; -}
ZOJ 3870 Team Formation