Обратите внимание, что это более подробная версия предыдущего закрытого вопроса.
У меня есть сценарий, в котором я
Код: Выделить всё
NКод: Выделить всё
NКод: Выделить всё
min_tempКод: Выделить всё
max_tempI need to find a setpoint temperature that maximizes the number of items where that setpoint is between their
Код: Выделить всё
min_tempКод: Выделить всё
max_tempA brute-force approach would be to loop through possible temperatures at a certain step size, such as:
Код: Выделить всё
float best_temp;
size_t best_num_items = 0;
for(float t = -60; t < 100; t += 0.1) {
size_t num_items = 0;
for(auto item: items) {
if(t >= item.min_temp && t best_num_items) {
best_num_items = num_items;
best_temp = t;
}
}
Is there a non-brute-force approach that I should consider for this?
Источник: https://stackoverflow.com/questions/781 ... ge-revised
Мобильная версия