Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<typename F>
- int FindFloor(int n, F m) {
- int low = 1;
- int high = n;
- while (low < high) {
- int mid = (high + low) / 2;
- if (m(mid)) {
- high = mid;
- }
- else {
- low = mid + 1;
- }
- }
- return low;
- }
- int main() {
- int n, t;
- cout << "Enter n and target floor number: "s << endl;
- cin >> n >> t;
- int count = 0;
- int found = FindFloor(n, [t, &count](int f) {
- ++count;
- return f >= t;
- });
- cout << "Found floor "s << found << " after "s << count << " drops"s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement