mathturbator's blog

By mathturbator, history, 10 years ago, In English

I have tested it against small test cases and all boundary cases but am still not able to find what the error is. Can somebody please guide/help me. Here is the link to my submission. Thanks in advance :)

http://mirror.codeforces.com/contest/552/submission/11695423

  • Vote: I like it
  • -6
  • Vote: I do not like it

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

i guess it's precision problem..avoid using floats may be..

  • »
    »
    10 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    But am not using it to calculate anything, just using it to calculate slope, which will be same even if my numerator and denominator are different(as in they still have same gcd to give same slope). I even used double. Its still wrong answer for test case 4.

    • »
      »
      »
      10 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      you can't compare double like this:

      if(s2==slope and intercept==in){
      	m[mp(slope,intercept)]++;
      }
      

      see this link

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

Never trust in doubles :v , i mean that when you are using float , double , long double you can't compare with == , < , > as usual integer comparation , this issue happens because you are using operation a real number(can have infinite decimal digits — decimal periodic) in a double and you will lose precision because the number is truncated in some decimals , it is convenient to compare doubles with

abs(x - y) <  = EPS where EPS = 1e - 8

its enough for almost of problems or you need to change of focus and use only integers.

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

In calculating slope, one way is to keep it in p/q form where p and q are coprimes.