GRIDPNT - Grid points

There's a Cartesian lattice with 0<=x,y<=n. Given one point (x1, y1>0) in this lattice rotating clockwise as little as possible around the origin find the next point (x2, y2). The given and searched points mustn't have another point between the origin (0, 0) and this point itself.
x1, y1, x2, y2 are non-negative integers.

GraphGridPnt

Score is source length.

Input

In the first line the number T (T<100) of test cases.
Then T lines with the space-separated n (1<=n<=50), x1 and y1.

Output

For each test case the space-separated x2 and y2.

Example

Input:
3
1 1 1
5 3 2
50 48 49 Output: 1 0
5 3
49 50

Added by:HWK
Date:2011-05-24
Time limit:9.989s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2013-06-25 06:13:18 coding_express
i have posted my code in forum as wa in gridpnt,please check and reply
2013-06-25 06:02:22 coding_express
tricky test cases please
2012-11-23 08:24:40 Aditya Pande
should o(n) solution work for the speed variation of this problem


Last edit: 2012-11-23 08:29:05
2012-11-16 12:05:22 Mitch Schwartz
@Aditya: Yes, the input is well formatted, else my AWK solution couldn't pass.
2012-11-16 06:57:33 Aditya Pande
@mitch can u confirm that is the each input test case is on one line or not?
i doubt it is bcoz my AWK submission keeps getting NZEC but C submission works since C is more robust when input is on one or more than one lines
@mitch: thanks i got it

Last edit: 2012-11-17 12:17:35
2012-11-09 03:04:47 Mitch Schwartz
"(x1, y1>0)" is confusing, since the intention is "(x1>=0, y1>0)".
2012-08-07 19:43:55 Aditya Pande
my AWK submission is getting NZEC
EDIT: got it

Last edit: 2012-11-17 12:17:14
2012-08-07 19:43:55 Aditya Pande


Last edit: 2012-11-16 08:20:14
2012-08-07 19:43:55 HWK
@Johan de Ruiter: You could reach at least 133 bytes. ;-)
Edit: Your algo tried with Bash -> 81 bytes.
Edit 2: Python 129 bytes.
Edit 3: Jander reached 80 bytes with Perl.

Last edit: 2011-07-19 20:53:43
2012-08-07 19:43:55 HWK
@XeRon!X: With a new algo reached 94 bytes. ;-)

Last edit: 2011-06-27 12:13:04
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.