forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ab397a
commit 1ab873b
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(cpp_0458) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
add_executable(cpp_0458 main.cpp) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// Source : https://leetcode.com/problems/poor-pigs/ | ||
/// Author : liuyubobobo | ||
/// Time : 2019-05-02 | ||
|
||
#include <iostream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
|
||
/// Mathematics | ||
/// A better explanation than official solution if here: | ||
/// https://leetcode.com/problems/poor-pigs/discuss/94266/Another-explanation-and-solution | ||
/// | ||
/// Time Complexity: O(log(buckets)) | ||
/// Space Complexity: O(1) | ||
class Solution { | ||
public: | ||
int poorPigs(int buckets, int minutesToDie, int minutesToTest) { | ||
|
||
int res = 0; | ||
while((int)pow(minutesToTest / minutesToDie + 1, res) < buckets) | ||
res ++; | ||
return res; | ||
} | ||
}; | ||
|
||
|
||
int main() { | ||
|
||
return 0; | ||
} |