水题
#include <iostream> using namespace std; int cnt, n, u, d; void GreedySelector() { int sum = 0; cnt = 0; while(1) { sum += u; ++cnt; if( sum >= n ) break; sum -= d; ++cnt; } } int main() { while ( cin >> n >> u >> d && n && u && d ) { GreedySelector(); cout << cnt << endl; } return 0; }
贪心算法爬楼问题
本文介绍了一个基于贪心算法的爬楼问题解决方案。通过不断选择上升或下降一定距离来达到目标楼层,算法实现了最小步数求解。适用于算法初学者理解和实践。

被折叠的 条评论
为什么被折叠?



