C++ 最少切割次数:将 n 根木棍切成 0 的算法
#include
int main() { int n; cin >> n;
int ans = 0;
int length = 1;
while (n > 0) {
if (n >= length) {
n -= length;
length++;
ans++;
} else {
length = 1;
}
}
cout << ans << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/pWGs 著作权归作者所有。请勿转载和采集!