Answer the question
In order to leave comments, you need to log in
Inappropriately high value?
The algorithm must find the minimum values from a two-dimensional vector and add them to the cost variable until the condition is met, but the answer is -15166, although there can be no negative numbers there. I don't know where to dig already..
short cost = 0 ,mass=0;
short min=10000, min_x, min_y;
for (; true;) { //поиск минимальных значений
for (int i = 0; i < x; i++) {
for (int k = 0; k < y; k++) {
if (field_price[i][k] < min && field_price[i][k] != 0) {
min = field_price[i][k];
min_x = i;
min_y = k;
}
}
}
mass += field_mass[min_x][min_y];
field_price[min_x][min_y] = 10000;
if (mass > size) {
cout << cost;
return 1;
}
cost += min;
min = 100000;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question