Uva 10137 the trip

Nov 17, 2009

Problem: 10137.the trip

Tips:
1.
If (currentStudentPayment > averagePayment)
positiveDifference += currentStudentPayment - averagePayment;
Else
negativeDifference += averagePayment - currentStudentPayment;

if(negativeDifference > positiveDifference)
return negativeDifference
else
return positiveDifference

2. Here negative or positive difference must be int which is the tic of this problem More
Specific hinds:
he problem with this problem may be related to precision error. Here is solution by Neilor:
double highx = (int)((total/n+0.0099)*100);
double lowx = (int)((total/n)*100);
highx /= 100;
lowx /= 100;
Where total is the total sum of the money and n is the number of students.

Then, test each student money if is > than highx or < than lowx, accumulate (student[i]-highx) or (lowx-students[i]), respectively.
Then, output the variable that have the bigger value.

Code In C/C++:

No comments:

Post a Comment