# The Hotel with Infinite Rooms(UVA10170) ## [程式繳交區](https://hackmd.io/@Renektonn/Skv4dd0vkl/edit) ## 題目 [點我](https://onlinejudge.org/external/101/10170.pdf) ## 解題網站 [UVA](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1111) [ZJ](https://zerojudge.tw/ShowProblem?problemid=e555) ## 演算法 ``` 1. 輸入s,d 若無法則停止 2. 定義nd=1 3. 當nd小於等於d nd += s s++ 4. 輸出s - 1 ``` :::info nd跟s的關係是什麼 迴圈結束時,會滿足甚麼條件 ::: ## 程式碼 ```cpp= #include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll s, d; while (cin >> s >> d) { ll nd = 1; while (nd <= d) { nd += s; s++; } cout << s - 1 << endl; } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up