-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd98.cpp
More file actions
55 lines (51 loc) · 918 Bytes
/
d98.cpp
File metadata and controls
55 lines (51 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include "Header.h"
#include <string>
using namespace std;
int d98() {
bool fl = true;
int n, k, P;
while (fl) {
fl = false;
cout << "98) write n(colvo stypenek), k(colvo orehov) and P(prochnost)" << endl;
n = getInt();
k = getInt();
P = getInt();
if (n <= 0 || k <= 0 || P<=0) {
cout << "n <= 0 or k <= 0. try again" << endl;
fl = true;
}
}
if (n == 1) {
cout << "ans: 1" << endl;
}
else if (n < P) {
cout << "oreh ne razobjetsa. n<P" << endl;
}
else {
int start = 0, end = n, center = 0, ans = 0;
while (center != P) {
center = (start + end + 1) / 2; // Ïîèñê ñåðåäèíû
if (P > center)
{
start = center;
}
else if (P < center)
{
end = center;
}
else
{
break;
}
ans += 1;
}
if (ans > k) {
cout << "malo orehov" << endl;
}
else {
cout << "minimum colvo popitok: " << ans << endl;
}
}
return 0;
}