# 20191214TOI新手同好會 1.黃金比例 --- 題目連結:https://zerojudge.tw/ShowProblem?problemid=e794 --- ```clike= #include<iostream> using namespace std; int main(){ int n, w = 1, h = 1, n1 = 0, n2 = 1; cin >> n; for(int i = 1; i <= n; i++){ if(i != n) w = n1 + n2; h = n1 + n2; n1 = n2; n2 = h; } cout << w << ":" << h; return 0; } ``` --- 一開始用遞迴,結果TLE,猜測可能是因為呼叫兩次函式(然後發現自己的遞迴不太熟練)。 後來還是用老方法跑迴圈,要注意的是寬為n,高為n+1,所以最後一遍w不用加,或是最後取最小值最大值。
×
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