Reputation: 83
There's a discrete binary search article on topcoder where i met with this expression.
while(lo & lt; hi )
if(i + j & lt ; = x )
described below
I have never seen this expression ";" in a while loop and using & in it.
And Also, in general i want to know what AND &
bit wise operator do(i know how it works in binary level but i wanted to know how the final result can be calculated without converted numbers into binary forms) and also the if statement in below code.
int getMostWork(vector folders, int workers) {
int n = folders.size();
int lo = * max_element(folders.begin(), folders.end());
int hi = accumulate(folders.begin(), folders.end(), 0);
while (lo & lt; hi) {
int x = lo + (hi - lo) / 2;
int required = 1, current_load = 0;
for (int i = 0; i & lt; n; ++i) {
if (current_load + folders[i] & lt; = x) {
// the current worker can handle it
current_load += folders[i];
} else {
// assign next worker
++required;
current_load = folders[i];
}
}
if (required & lt; = workers)
hi = x;
else
lo = x + 1;
}
return lo;
}
Upvotes: 1
Views: 462
Reputation: 3923
This is just bad formatting of the HTML for the "<" less than operator from wherever you found this code
The HTMLcode for <
is <
Replace all sequences of <
with <
and you get:
while (lo < hi) {
int x = lo + (hi - lo) / 2;
int required = 1, current_load = 0;
for (int i = 0; i < n; ++i) {
if (current_load + folders[i] <= x) {
// the current worker can handle it
current_load += folders[i];
}
else {
// assign next worker
++required;
current_load = folders[i];
}
}
if (required <= workers)
hi = x;
else
lo = x + 1;
}
No bitwise AND operator, just less than conditionals
Upvotes: 6