Here, for example, the simplest olympiad problem. I solved it in 45 minutes, in the old fashioned way, with oop:

  1. I create class AppleTree
  2. I am writing a comparator
  3. I make a dynamic array and sort it.
  4. I use a couple of crutches to know where the nearest trees are to the zero position.
  5. I clone a dynamic array
  6. I walk recursively in an array, deleting trees
  7. Then go to the other side of the sloped array

This is all taking into account the search for bugs took me three-quarters of an hour. And if you look, then some people managed to solve it in 5 minutes!

Well, for 5 minutes, I definitely will not succeed. But at least 20 ...

Well, the question is how to achieve this. Since the overwhelming number of time took writings, then we must somehow reduce it. But how to do that? I understand that it is not necessary to fence an oopgorod, but how not to fence it?

ps Those who will propose to close the question for "it is necessary to concretize the question," etc. - I specifically cited a specific task. In my opinion this is a sufficient specification.

  • 3
    People who are engaged in Olympiad programming usually at some point recruit a huge number of algorithmic patterns. They literally copy the finished template and quickly rule it. In addition, tasks like "recursively bypass the array" do not cause them to think at all and fly out from under their fingers without any bugs at all. Because they solved them a hundred or so times. That's from there 5 minutes and is taken - Duck Learns to Take Cover
  • Specifically, this problem is solved by much less effort: - Yaant
  • @Yaant exactly? - kandi
  • I did not add this - I clicked the enter to transfer the line, but I took a comment and posted it. :) So: 1) Fill the source data, depending on the sign of x_i, into two arrays sorted modulo x. 2) we sum up the a_i values ​​from both arrays from 0 to n, where n is the length of the smaller of the arrays (assuming that the indexing of the arrays starts from 0, and a [length (a)] = 0). Actually, everything. - Yaant

2 answers 2

I understand that it is not necessary to fence an oopgorod, but how not to fence it?

One function, or even just a couple of lines in main. All Olympiad tasks are divided into several types:

  • To implement: (requires knowledge of a certain algorithm and the ability to quickly and correctly zadalit).
  • On wit: (the type of answer is always the same or 2 possible, for this you should practice solving the problems on a piece of paper and calculate algorithmic patterns).
  • Brutus force: (tasks that are solved by exhaustive search; for such tasks, sufficient experience and the correct ability of algorithmic complexity are necessary in order to assess in advance whether your algorithm will give the correct answer).
  • Divide and conquer: (some tasks when dividing them into subtasks are solved in 4 lines).
  • Reduction of tasks to existing ones: (with enough experience, you will be able to reduce some tasks to others).

And in general, apart from experience, there’s nothing to help you, all problems are basically solved in 10-25 lines of code (except for paragraph 1, but there are not so many of them). Learn the best STL and go ahead. First you must know the algorithm that you are writing, and after you write it!

    The topic is actually not specific enough, because the question is not at all asked.

    And there is only one recipe, and it is very “simple”: to fill your hand, to solve as many tasks as possible, then typical solutions will be implemented “on the machine”. Well, to sort out other people's good decisions, adopting the right practice.