Team formation Zhejiang race (XOR)

Source: Internet
Author: User

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&LT;&LT;J)) break; } if (j) {for (; j>=0;j--) if (!) (                   a[i]& (1&LT;&LT;J))) ant+=bit[j];    }}} printf ("%lld\n", ant); } return 0;}


Team formation Zhejiang race (XOR)

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.