You complete me

Here is a list of 1 0 5 10^5 distinct 32-bit unsigned integers .

Any two of them are called complementary if their bitwise XOR is composed of all 1 s and no 0 s.

How many complimentary pairs are there in this data set?


The answer is 0.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <cstdio>
#include <map>
using namespace std;
int main()
{
    map <int, char> m;
    unsigned int a;
    int counter = 0;
    for(int i = 0; i < 100000; i++){
        scanf("%u", &a);
        if(m.find(~a) != m.end()) counter += 1;
        m[a] = 1;
    }
    printf("%d", counter);  
}

Spencer Whitehead
Oct 16, 2016

A simple map does the trick--include all A[i], then check the map for the number of occurrences of ~A[i] for each i

True. Can you share your code?

Agnishom Chattopadhyay - 4 years, 8 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...