Skip to content

Add 0029 #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions md/0029.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ถ้ากบกระโดดเป็นระยะทางครั้งละ $X$ หน่วยไปยังจุดหมายที่ห่างออกไป $Y$ หน่วย จะมีความเป็นไปได้ 2 กรณีหลัก ๆ
1. ถ้า $X > Y$ กบจะต้องกระโดด $2$ ครั้งเพื่อไปยังจุดหมาย ตามรูป
2. ถ้า $X \le Y$ กบจะสามารถกระโดด $\left\lceil \frac{Y}{X} \right\rceil - 2$ ครั้งไปในทิศทางของ $Y$ และกระโดดอีกกระโดดอีก 2 ครั้งเพื่อไปให้ถึงจุดหมายได้เสมอเนื่องจากระยะห่างที่เหลือในการกระโดดสองครั้งสุดท้ายจะน้อยกว่า $2 \cdot X$

![](../media/0029/jump.png)

```cpp
#include<bits/stdc++.h>
using namespace std;

int main () {
int x, y;
cin >> x >> y;
if (x > y) cout << "2\n";
else cout << (y + x - 1) / x << "\n";
return 0;
}
```
Binary file added media/0029/jump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.