[Transfer from Codeforces] How to come up with the solutions:techniques

Source: Internet
Author: User

As I work with students I often face the situation when if a problem doesn ' t seem clear to a student at the first sight, I T makes them unable to solve it. Indeed, hear about specific methods and techniques. But you don ' t hear on how to think in order to apply them. In this note I'll try to sum up my experience of solving programming contest problems. However, some pieces of advice would also be applicable-Olympiads in mathematics and your first steps in academic Resea Rch.

So you've read a problem and you don ' t know what to solve it. Try the following techniques, some of them can often come handy.

Technique 1: "Total Recall"

Try to remember some similar problems so you had to solve. Quite Many problems do not has a brand new idea. So probably, you can use your experience of solving a similar problem to solve this one.

Technique 2: "From the specific to the general"

Let's say that ' ve found the solution for the problem (hurray!). Let's consider some particular case of a problem. Of course, you can apply the algorithm/solution to it. That's why, in order to solve a general problem, you need to solve all of its specific cases. Try solving some (or multiple) specific cases and then try and generalize them to the solution of the main problem. Such specific cases can be regarded as the simplifications of the problem, i.e. we can reason by the following principle: "If I don ' t know how to solve a complex problem, I think I ' ll simplify it and find the solutions of the simplified version ".

The popular examples of simplifications (specific cases):

    • You get a problem for a tree. Consider its variant where the tree degenerates into a path;
    • The problem has weights? Consider a variant where all the weights is equal either to one or to an arbitrary number, or there is only one distinct Weights (and so on).

Note that the solution of a specific case almost always isn ' t easier than the solution of a in general one, so you need to TR Y and find a solution that would is as easy and effective as possible.

Technique 3: "Bold hypothesis"

Don ' t be shy of making bold hypotheses this seem true to you. Prove your solutions during contests, tap your inner intuition. When your ' ve come up with your hypothesis, try to prove it-it could either work out well or give what do you have to disp Rove it. Do test the hypothesis on a wide set of tests as it would is a pain to waste time on implementing a solution based on a HY Pothesis and only after that disprove the hypothesis.

Examples:

    • The solution always exists;
    • Item the number of states isn ' t large.
Technique 4: "To solve a problem, you should think like a problem"

I ' m serious, put yourself in the shoes of the character of the problem, imagine that it's your job to handle the input set S. Think about what you ' d act in the case. Try to process some small samples on your own. If the problem is about a game, play it. Sometimes I try to visualize a process or a model for better understanding. It's a little like how movies show the scientists think. Try to think in images, imagine the solution, see it unfolding.

Technique 5: "Think together"

This technique was only applicable to team contests. In group of, or three persons start saying some clear facts about the problem. For example: "If n was even, then the answer was always 0", "If n was prime, then the solution should go", and so O N. Sometimes your teammates would pick up ideas and develop them and this strategy can get you through the problem.

Technique 6: "Pick a Method"

Try coming through popular algorithms or methods that can apply to the problem on any. It's useful to see the problem limits. Have picked a method, try thinking on the solution assuming that the problem are solved using this method. Your reasonings should was somewhat like this: "Let's assume that the problem was solved by divide and conquer." Then let us solve this problem recursively for the left and right half. Now all that's left was to find a by-unite these solutions. I wonder how we can does that ... "

Technique 7: "Print out and look"

Quite often (especially in problems with a small input:one/two numbers) there is some patterns in the composition of the Solution. To see a pattern, you sometimes need to write some naive method of solving a problem, generate answers for a large number of tests on large limits and meditate on your answers for a while. In order keep the computer busy, a good strategy are to print out the acquired results and meditate this time on the Print outs.

Sometimes it is a good idea to print isn't only the answer, but also some extra information, such as a manner of acquiring a Solutions.

Technique 8: "Google"

This technique can is used if the Round/contest rules allow it. If the problem is about sequences and then you can look for solutions (see Technique 7) on the site https://oeis.org/. It helps to understand the formal model of the problem and Google the correct mathematical terms

[transfer from codeforces] How to come up with the solutions:techniques

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.