Nakagawa.Kanon's blog

By Nakagawa.Kanon, history, 6 years ago, In English

Recently I've been submited some pratice code to solve the Edgy Baking problem of Google code jam but there always are some error in my output, even thought the difference never exceed 0.01 as I've tested some random input. Can someone please check it ? https://pastebin.com/526V81qR

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Nakagawa.Kanon (previous revision, new revision, compare).

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Nakagawa.Kanon (previous revision, new revision, compare).

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I don't know about the correctness of your code, but I can for sure tell about dealing with precision issues. Firstly, your code uses float. Generally people tend to use doubles as it has double the precision as that of the float. Secondly, if something like this is written, the absolute value of the relative error between your answer and the checker's answer must not exceed 1e-6, then it's safe to ensure that we output 6 digits after the decimal for the floating point number. It can be done with printf as : printf("%.6lf", var), where var is a double. and with cout as cout << fixed << setprecision(6).

If your code is only suffering from precision issues, these workarounds are enough.

P.S.: Haven't tried it much, but I think having a greater no. of digits after the decimal point than just 6 might also not hurt as well. So, you might try a larger no. of digits after the decimal point as well.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you so much. I have just begun to learn coding, this might be a big help.