Here is the problem statement
http://www.spoj.com/problems/MYQ1/
This task requires a little bit of logic to solve.
RowNo Left Right
W A A M W
01
1 02 03 04 05 06
2 11 10 09 08 07
3 12 13 14 15 16
4 21 20 19 18 17
5 22 ............
This is the structure of the bus. Calculating the row will be very easy .
Here is the pseudocode of calculating the position of the row.
n=n-1;(To consider numeration from 1 )
row=n/5;
n=n-row*5;
if(n>0)
row++;
Then we need to check every single remainder when n is divided on 5.
Let's have a look at a table where we write only the remainder of n divided on 5
2 3 4 0 1
1 0 4 3 2
..............
................
and so on. If the number of row is not divisible on 2 then we should consider 2,3,4,0,1 else 1,0,4,3,2
http://www.spoj.com/problems/MYQ1/
This task requires a little bit of logic to solve.
RowNo Left Right
W A A M W
01
1 02 03 04 05 06
2 11 10 09 08 07
3 12 13 14 15 16
4 21 20 19 18 17
5 22 ............
This is the structure of the bus. Calculating the row will be very easy .
Here is the pseudocode of calculating the position of the row.
n=n-1;(To consider numeration from 1 )
row=n/5;
n=n-row*5;
if(n>0)
row++;
Then we need to check every single remainder when n is divided on 5.
Let's have a look at a table where we write only the remainder of n divided on 5
2 3 4 0 1
1 0 4 3 2
..............
................
and so on. If the number of row is not divisible on 2 then we should consider 2,3,4,0,1 else 1,0,4,3,2
No comments:
Post a Comment