andreyv's blog

By andreyv, 10 years ago, translation, In English

As you know, the C++ language assumes that the programmer is always correct. Therefore C++ compilers don't add additional checks to the program, such as checks for null pointer dereference or out-of-bounds array access. This is good, because C++ programs run as fast as possible, and this is bad, because sometimes we may spend a long time debugging some silly mistake. We would want that the compiler can find such mistakes automatically. And many compilers can! In this post I will show various GCC options that do this. Previously zakharvoit already wrote about this here.

All options that will follow should be added to the GCC command line. In various IDEs you can do it in IDE or compiler settings. Many of the options can also be used with Clang (for example, in Xcode). For MSVC++, I think, there is nothing better than Debug mode and /W4.

Full text and comments »

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

By andreyv, 12 years ago, translation, In English

TCO 2013 Algorithm Round 2A will be held today at 20:00 Moscow time. Those who previously advanced in Round 1 may compete in this round. Registration begins three hours before the contest. First 50 places advance to Round 3.

Full text and comments »

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

By andreyv, 12 years ago, translation, In English

Div. 2 A — Dragons

Observe that if Kirito fights a dragon whose strength is less than Kirito's strength, then Kirito does not lose anything — in fact, he even gains a nonnegative strength increase. Taking note of this, let's for each step choose some dragon whose strength is less than Kirito's current strength, and fight it. After performing some amount of these steps we'll eventually end up in one of these two situations: either all dragons are slain (then the answer is "YES"), or only dragons whose strength is not less than Kirito's strength remain (then the answer is "NO"). On each step we can choose a suitable dragon to fight either by searching through all dragons or by sorting the dragons by strength in non-descending order in advance.

The complexity of the solution is O(n2) or . Sample solution: http://pastie.org/4897164 (archived copy)

Full text and comments »

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

By andreyv, 12 years ago, translation, In English

Hello!

I wish to continue the discussion on C++ input/output performance, which was started by freopen long ago. freopen compared the speed of the two common input/output methods in C++: the stdio library, inherited from C (<stdio>), and the newer iostreams library (<iostream>/…). However, these tests did not account for the fact that there are several important iostreams optimizations which can be used. They have been mentioned more than once on Codeforces (first, second, third). I have written a program that compares performance of the stdio and iostreams libraries with these optimizations turned on.

Full text and comments »

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