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 1656. Far Away Kingdom's Army

what is the algorithm :?
Posted by 59838AD 18 Nov 2008 21:43
Re: what is the algorithm :?
Posted by Artem Litvinenko SSU 19 Nov 2008 01:11
the algorithm consist of transposition the most high soldier to the centre of the line and to the centre of the column. in cycle from 1 to n gives bubble sorting.
Re: what is the algorithm :?
Posted by melkiy 11 Mar 2009 07:05
Please can you explain how to do bubble sort in 2-d array here?
algorithm
Posted by melkiy 11 Mar 2009 07:14
I constructed such an algorithm. It requires the soldiers to be sorted by their height downwards.

When the soldiers are sorted, take them one by one and fill the square diamond by diamond, starting from center.
A "diamond" contains those cells (x,y) for which
|x - x_center| + |y - y_center| == C,
C ranges [0; n-1].

Edited by author 11.03.2009 08:54
Re: algorithm
Posted by Michail Yudin 11 Apr 2009 19:42
it's no solution
Re: algorithm
Posted by Daniel Mahu 10 Dec 2011 04:47
There is a much simpler method, which also uses less memory.

Hint: try a O(n) sort.
Also try not to store n*n elements in memory (print line by line instead).