mac_n_cheese_pog's blog

By mac_n_cheese_pog, history, 3 years ago, In English

yesterday there was a div2 contest,i was pretty confident since ive trained alot.so i decided to join.

after 5 minutes,i am able to solve A with paper.i have the informal proof.and i decided to code it out.turns out it fails the second pretest.i was testing for another random tc to see whether my approach is correct.turns out my approach is correct yet im unable to solve it until the contest ends.

after the contest,i saw the editorial.the editorial is slightly different than my approach but ive done the math and it was the same.now im suspecting that c++ is actually broken.why i say? because it cant handle decimals correctly.

i think most people has a potential but theyre unable to achieve it because of broken languages like c++.maybe someone can recommend me another language thats as fast as c++ and can handle numbers correctly?

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

»
3 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Considering that there are thousands of c++ solves I don't think that c++ is the issue...

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

    Yeah, c++ doesn't have that issue since you just use std::fixed and std::setprecision.

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

      the problem is on operation not printing.c++ miss like 0.1 or maybe less which leads to incorrectness

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

'because of broken languages like c++.'

Are you kidding me? I think it had nothing to do with which language you used.

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

    nope.my teacher never recommend using c++.he recommends using either java or python.i think i should listen to his advice

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      The main reason why people don't recommend C++ and instead recommend Python is because it has a simpler syntax and C++ is quite complex in terms of language features (and gives you more freedom in doing things). However, C++ can do things much more efficiently than Python. Not sure why your teacher recommended Java though (I suspect it is because there is just a single programming paradigm in Java which makes it easier to adhere to a pattern).

      Most high performance code is written in either C or C++, and more often than not, such code involves floating point arithmetic, so floating point arithmetic is definitely not an issue in C++, rather, it is what the IEEE 754 standard defines for floating point arithmetic that C++ follows.

      The issue with your way of implementing might be precision issues, since the standard defines arithmetic in terms of a mantissa and an exponent (in base 2, and not base 10). Note that you can't store things like 1/3 in a finite amount of space in such a representation in base 10. Similar things hold for base 2, so due to a space limitation, you need to sacrifice some precision. There exist ways to bound the error. If you want a higher precision, you should prefer double or long double, and also avoid multiplying very small and very large numbers (among other such ideas). These precision issues also arise in Python.

      There are arbitrary-precision floating-point libraries for each major language (you probably won't need them), but they're built into the language for Java and Python (for instance, the Python Decimal class). For arbitrary-precision integer computation, people prefer Python or implement their own libraries in C++ (which is not hard).

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

can we see the code, maybe we can find the issue

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

I think i get it, try adding this line in the starting of your code

cout<<setprecision(x);

where you can keep x>6 to be on safe side. You can read more about it from here.

PS : Clearly c++ is not the problem here.