Movatterモバイル変換


[0]ホーム

URL:


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

Commitb4fe037

Browse files
authored
Update readme.md
1 parent2f7f007 commitb4fe037

File tree

1 file changed

+27
-18
lines changed
  • src/main/java/g0301_0400/s0375_guess_number_higher_or_lower_ii

1 file changed

+27
-18
lines changed

‎src/main/java/g0301_0400/s0375_guess_number_higher_or_lower_ii/readme.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ Given a particular `n`, return _the minimum amount of money you need to **guaran
2020

2121
**Output:** 16
2222

23-
**Explanation:** The winning strategy is as follows:
24-
- The range is\[1,10\]. Guess 7.
25-
- If this is my number, your total is $0. Otherwise, you pay $7.
26-
- If my number is higher, the range is\[8,10\]. Guess 9.
27-
- If this is my number, your total is $7. Otherwise, you pay $9.
28-
- If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.
29-
- If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.
30-
- If my number is lower, the range is\[1,6\]. Guess 3.
31-
- If this is my number, your total is $7. Otherwise, you pay $3.
32-
- If my number is higher, the range is\[4,6\]. Guess 5.
33-
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.
34-
- If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.
35-
- If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.
36-
- If my number is lower, the range is\[1,2\]. Guess 1.
37-
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.
38-
- If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11. The worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.
23+
**Explanation:**
24+
25+
The winning strategy is as follows:
26+
- The range is [1,10]. Guess 7.
27+
- If this is my number, your total is $0. Otherwise, you pay $7.
28+
- If my number is higher, the range is [8,10]. Guess 9.
29+
- If this is my number, your total is $7. Otherwise, you pay $9.
30+
- If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.
31+
- If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.
32+
- If my number is lower, the range is [1,6]. Guess 3.
33+
- If this is my number, your total is $7. Otherwise, you pay $3.
34+
- If my number is higher, the range is [4,6]. Guess 5.
35+
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.
36+
- If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.
37+
- If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.
38+
- If my number is lower, the range is [1,2]. Guess 1.
39+
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.
40+
- If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11.
41+
The worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.
3942

4043
**Example 2:**
4144

@@ -51,8 +54,14 @@ Given a particular `n`, return _the minimum amount of money you need to **guaran
5154

5255
**Output:** 1
5356

54-
**Explanation:** There are two possible numbers, 1 and 2. - Guess 1. - If this is my number, your total is $0. Otherwise, you pay $1. - If my number is higher, it must be 2. Guess 2. Your total is $1. The worst case is that you pay $1.
57+
**Explanation:**
58+
59+
There are two possible numbers, 1 and 2.
60+
- Guess 1.
61+
- If this is my number, your total is $0. Otherwise, you pay $1.
62+
- If my number is higher, it must be 2. Guess 2. Your total is $1.
63+
The worst case is that you pay $1.
5564

5665
**Constraints:**
5766

58-
*`1 <= n <= 200`
67+
*`1 <= n <= 200`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp