### rishi_07's blog

By rishi_07, history, 4 years ago,

These are my codes for the problem Compression Algorithm of ACM ICPC 2018 online round.
I don't understand what is the problem with the first solution.
Note: The expected precision was 10^-6.
Image 1
Image 2

• +7

 » 4 years ago, # |   0 Auto comment: topic has been updated by rishi_07 (previous revision, new revision, compare).
 » 4 years ago, # | ← Rev. 5 →   +4 Well they say "Your answer will be considered correct if the absolute error is less than 10 - 6". With printf("%.6lf") there is possibility you will print something with error equal to 10 - 6 which is considered wrong.
•  » » 4 years ago, # ^ |   0 Hi, please check the first image. There I used setprecision(10). Still WA. This is not only my case, check this discussion on codechef Link
 » 4 years ago, # |   -20 I can explain why the setprecision code gives WA but I have no idea about the printf . setprecision includes the number of digits before the decimal point also . So setting it to 9 + 6 should work.
•  » » 4 years ago, # ^ |   0 In this Link user swetankmodi claimed to have used setprecision(18) but still got WA.
•  » » » 4 years ago, # ^ |   0 #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--) { long long int n, k; cin >> n >> k; long double ans = 2.0 * ((k-1)*n + 1) / k; cout << fixed << setprecision(16) << ans << endl; } } This gave us AC
•  » » » » 2 years ago, # ^ |   0 can you please explain the logic
•  » » » 4 years ago, # ^ |   +7 yes, but the solution posted by @bhishma uses long double but I used only double. Maybe that caused the issue?
•  » » 4 years ago, # ^ |   0 You're wrong. From http://www.cplusplus.com/reference/iomanip/setprecision/ "Sets the decimal precision to be used to format floating-point values on output operations". Beside we submitted with setprecision(8) and it got accepted.
•  » » » 4 years ago, # ^ |   +3 Actually my main language is Java so I might be wrong , but I have seen this issue in some old codeforces blog . In that case how can you explain this
 » 4 years ago, # |   +65 There is a difference between cout<
 » 7 weeks ago, # |   0 Can anyone explain the solution of this problem ? I have tried it for long but haven't come up with anything significant.