Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f815b0c

Browse files
solved leetcode daily challenge, Minimim Garden Perimiter to Collect Enough apples
1 parent e62309b commit f815b0c

File tree

1 file changed

+66
-0
lines changed
  • LeetCode/Minimum_Garden_Perimeter_to_Collect_Enough_Apples

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
#include <gtest/gtest.h>
3+
using namespace std;
4+
5+
6+
//// START
7+
/*
8+
## Minimum Garden Perimeter to Collect Enough Apples
9+
10+
*/
11+
12+
/*
13+
*
14+
0.0
15+
1.0 1.1 1.2 1.3
16+
2.0 2.1 2.2 2.3
17+
3.0 3.1 3.2 3.3
18+
*/
19+
20+
21+
// (n+1)*n * n
22+
class Solution {
23+
public:
24+
long long minimumPerimeter(long long neededApples) {
25+
long long left = 1;
26+
int n = cbrt(neededApples/4);
27+
while(sum(n) < neededApples){
28+
n++;
29+
}
30+
return n*8;
31+
}
32+
private:
33+
long long sum(long long n) {
34+
return (n+1)*n /2 * (n+n+1) * 4;
35+
}
36+
};
37+
38+
//// END
39+
struct T {
40+
41+
};
42+
43+
TEST(Solution, test) {
44+
T ts[] = {
45+
{
46+
47+
},
48+
{
49+
50+
},
51+
52+
};
53+
54+
for (T t : ts) {
55+
Solution solution;
56+
57+
}
58+
}
59+
60+
int main() {
61+
testing::InitGoogleTest();
62+
63+
return RUN_ALL_TESTS();
64+
}
65+
66+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /