ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1313. Some Words about Sport

HINT
Posted by Varun Sharma 6 May 2009 10:26
Hi,

Well it took me a while to figure out as to how to approach this problem but as it turned out it is pretty straightforward. I divided the problem into two parts. First I printed out the elements up until the middle diagonal. And then the elements after that.

Here is the format of the numbers for 4 X 4 array

0,0  0,1  0,2  0,3
1,0  1,1  1,2  1,3
2,0  2,1  2,2  2,3
3,0  3,1  3,2  3,3

We can see a pattern here. First print the element 0,0.

Then -> 1,0 to 0,1    (i = 1 to i = 0 and j = 0 to j = 1)
Then -> 2,0 to 0,2    (i = 2 to i = 0 and j = 0 to j = 2)
Then -> 3,0 to 0,3    (i = 3 to i = 0 and j = 0 to j = 3)

So, basically as we are heading towards the main diagonal, we are increasing the value of i and at the same time running j from 0 to i.

Implementing this will get you the first 10 out of 16. For the rest of them, we have the same pattern again but this time its reverse

Then -> 3,1 to 1,3    (i = 3 to i = 1 and j = 1 to j = 3)
Then -> 3,2 to 2,3    (i = 3 to i = 2 and j = 2 to j = 3)
Then the last element 3,3

So, this just requires some clever manipulation of the for loops or while loops.
Re: HINT
Posted by Lifeisbeautiful 23 Dec 2020 12:53
Thank you!
Re: HINT
Posted by Igor Mallea 7 Jun 2021 10:23
Thank you very much!!!