Team Formation
Test instructions: Select two teams in N troop species to satisfy (i.e. A ⊙ B > max{ A , B }). N<1e5 time: 2s
Analysis: First for each team member of the skill level processing, with the binary representation of the location of the record 1, with the array bit "" to save;
Traversing an element, where 0 of the position is present in the binary, the binary of the bit array here is 1, which can be stored in and computed for all and all.
# include<iostream> #include <cstdio> #include <cstring> #include <string>using namespace std; const int maxn=100000+5;# define LLD long Longint a[maxn];int bit[50];int main () {int t; cin>>t; while (t--) {int n,i,j; cin>>n; memset (bit,0,sizeof (bit)); for (i=0;i<n;i++) {scanf ("%d", &a[i]); for (j=31;j>=0;j--) if (a[i]& (1<<j)) {bit[j]++; } LLD ant=0; for (i=0;i<n;i++) {if (A[i]) {for (j=31;j>=0;j--) {if (a[i]& (1<<J)) break; } if (j) {for (; j>=0;j--) if (!) ( a[i]& (1<<J))) ant+=bit[j]; }}} printf ("%lld\n", ant); } return 0;}
Team formation Zhejiang race (XOR)