-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
458.cpp
22 lines (22 loc) · 894 Bytes
/
458.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
int t = (minutesToTest - 1) / minutesToDie + 1;
if (buckets == 1) return 0;
return log(buckets - 1) / log(t + 1) + 1;
}
};
__________________________________________________________________________________________________
sample 8136 kb submission
class Solution {
public:
int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
int matrix_size = minutesToTest / minutesToDie + 1;
int num_dimensions = 0;
while (pow(matrix_size, num_dimensions) < buckets) ++num_dimensions;
return num_dimensions;
}
};
__________________________________________________________________________________________________