kelzzin2_fan's blog

By kelzzin2_fan, history, 12 months ago, In English

Hello, I recently encountered a problem on Kattis which seems to be just be an implementation problem with precision issues that might need to be handled. However, after several WAs with no leads, I am at a dead end. I'm not even sure if it's precision related at the moment...

Below is my approach:

My Approach

My code:

My Code

Any help would be appreciated, thanks!

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
12 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Whatever you are doing inside the loop isn't very clear. Also, never do integral arithmetic in the real number domain. Google Stern-Brocot_tree.

  • »
    »
    12 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The while loop here serves 2 purposes, i1 and i2 here represent the index of the decimal point if any, I wanted C and F to be integers, so I calculate k = some power of 10 and try to "multiply" C and F into integers. Lastly I parse it into actual integers by removing the decimal point.

    Since I multiplied by k, I have to divide by k as well to get A back. Hence the floor/ceil division happening later down the line. This means all arithmetic should be only done with integers supposedly.

    Thanks for the pointer for Stern-Brocot_tree tho!