Created
October 21, 2019 18:25
-
-
Save dionyziz/4454cb28910250bc26794386a418b1b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
const int N = 10; | |
int numbers[] = {0, 2, 1, 3, 10, 4, 6, 7, 8, 5}; | |
int answer = 0; | |
for (int bit = 0; (1 << bit) <= N; ++bit) { | |
int cnt_expected = 0, cnt_actual = 0; | |
for (int i = 0; i <= N; ++i) { | |
cnt_expected += (i & (1 << bit)) != 0; | |
} | |
for (auto i: numbers) { | |
cnt_actual += (i & (1 << bit)) != 0; | |
} | |
if (cnt_expected > cnt_actual) { | |
answer |= 1 << bit; | |
} | |
} | |
cout << answer << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment