Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя aryan_agrawal

Автор aryan_agrawal, история, 4 года назад, По-английски

Hello everyone, this is Aryan. I am new to this platform as well as competitive programming. I just wanted to ask all of you , how dou think a question on reading it.

I will give you an example. In the CodeChef In september Lunchtime. The Watermelon problem (link : https://www.codechef.com/LTIME88B/problems/WATMELON)

After reading the problem I started putting all kinds of condition and for loop and stuff but still wasn't able to get the right answer. After the competition got over, and I read the solutions. It was just finding the sum and figuring out weather its greater than 0.

That was so easy, but only if you get to think like that.

So I wanted to ask you guys how you think out of the box or rationally after you read the question.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +49 Проголосовать: не нравится

It seems to me like you start coding before you know what you want to code. This is generally not a good idea, since you usually end up submitting incorrect solutions.

Before you start writing any code, you should have at least a basic idea of how you will solve the problem. You should also be at least somewhat confident in your idea, either through just a gut feeling or through proof. Although the online judge is there to check your solution, submitting solutions without having any idea if they're right is bad for both your score (in terms of penalty) and time (since you have to write a bunch of different programs and the delete them).

Generally, as you practice more you will get a better intuition on how to solve problems. For the specific problem you linked, my thought process goes something like this: Our goal is to make the sum of the array equal to 0. The way we can do this is by decreasing some number in the array. Now, we can observe two things. Firstly, we do not care about the specific value for each element in the array — we only care about the sum. Second, based on the first observation, we can conclude it does not matter which element we are decreasing, since the sum will change by -1 either way.

Now, there's no way for us to make the sum increase — our only option is to decrease. So if the sum is already negative, we can't make it 0 since that would require increasing the sum. Otherwise if the sum is greater or equal to 0, we can decrease until it becomes 0.

Usually problems in CF and CC require some observations, which should become easier for you as you practice and learn to recognize patterns.