【 OJ 】 HDOJ1049 18年12月19日16:09 [ 43 ]
阿新 • • 發佈:2018-12-23
這題模擬就好了....一直模擬u d 到出坑,看結果..當然最簡單的還是找規律...用公式來計算...有點煩..懶得找了直接模擬AC了
# include<iostream> using namespace std; int main(void) { int n, u, d; int time , distance; cin >> n >> u >> d; while (n || u || d) { time = distance = 0; while(++time) { if (time & 1) {//奇數跑 distance += u; } else {//偶數落 distance -= d; continue; } if (distance >= n)break;//模擬出結果 } cout << time << endl;//結果 cin >> n >> u >> d;//下一次迴圈 } system("pause"); return 0; }