← Back to topics
Topic

Precision in the problem "Paycheck" (08/09 Quals #2)

T
TheFlash92
My solution for the problem "Paycheck" was judged as incorrect (wrong answer) during the competition. However, I found out that it was due to the setprecision C++ function (which I used). It turns out that it rounds to the closest value, instead of truncating it, and the problem statement doesn't say results should be truncated instead of rounded. In fact, rounding the result is more precise than truncating. Example input:
3
1 1 1 2 1 2
The output by truncating is: 1.66
The output by rounding is: 1.67
But only the output calculated by truncating is judged as correct! So, everyone who was calculating the output by rounding got 0 points on that problem. Are you sure that it is OK to score problems this way?
p
picsel
My program in Pascal gives the result 1.67 for your test case, and I got 100 points.
a
adminModerator
That is not how the problem is graded.

If the correct value is 1.6666666 then any value between 1.65666666 and 1.6766666 is judged as correct
T
TheFlash92
That's weird. When I replaced the "setprecision" with division and multiplication by 100, and submitted in the training area, it was judged as correct... So setprecision is giving incorrect results somehow, but why?
a
adminModerator
Here is the checker's code

using namespace std;

int main(int argc, char *argv[]){

ifstream inFile(argv[1]);
ifstream outFile(argv[2]);
ifstream solFile(argv[3]);

double A, B;

solFile >> A;
if (!outFile.eof()) {
outFile >> B;
if (abs(A - B) <= 0.01)
cout << 1;
else
cout << 0;
} else {
cout << 0;
}

inFile.close();
outFile.close();
solFile.close();
return 0;
}