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 except: SCM qobi

hide comments
2011-06-03 14:07:11 HWK
On BINCLOCK it takes me 32 bytes from binary to hh:mm:ss. Is this too much?

Edit: I have to say that my binary and hh:mm:ss are of a 'special kind'. Error checking is done at the hh:mm:ss.

Last edit: 2011-06-03 14:28:12
2011-06-03 13:30:02 Jander
I had pondered on making up a collection of Perl golf tricks. It'd be interesting to do it as a collective as we all have different ways of achieving the same goal.

As to BINCLOCK, well I'm finding it very 'expensive' to go from the binary to the hh:mm:ss representation :-( I'm sure there's a better way.
2011-06-03 12:59:42 HWK
@Jander: I think on BINCLOCK it's more the 'algo' than simple shortening tricks.
A good idea could be to collect and publish shortening tricks for each language. There are few websites with only few tricks where you can 'learn' shortening. Thus for me as somebody who didn't know Perl before taking part in this contest it was difficult to get good Perl results. Hence on some tasks I required a lot of shots and a lot of time to get my shortest solution.

Last edit: 2011-06-03 14:08:18
2011-06-03 10:28:50 Jander
@HWK: I might submit some one day :-) There are a few tricks I'm still missing, eg how on earth you've got so low on BINCLOCK, and some of the other ones where I'm just one byte off the top Perl score. What is good though is when I figure out a new technique and can apply that to old submissions.

Last edit: 2011-06-03 10:41:00
2011-06-03 09:28:22 HWK
@hallvabo: I'm sure you've got still a lot of ideas but that's my kind to challenge you. Piotr Kakol alias challenger prefers another one.
For submitting challenges look here: http://www.spoj.pl/tutorials/PS/
@Jander: It really does though many tricks are already known. If you're interested in getting insights too look at the above link. I'm yet looking forward to your challenges. :-)
2011-06-02 19:49:10 Hallvard Norheim Bø
@HWK: I've just started on this challenge, got plenty of ideas left to try ;-)
How do I submit self-made challenges for SHORTEN?
2011-06-02 19:43:09 Jander
@HWK: It must give you quite an insight into how we work these things out, being able to see what our submissions actually are :-)

Last edit: 2011-06-02 19:43:28
2011-06-02 17:15:03 HWK
@hallvabo: Good work but my Python solution requires only 148 bytes. ;-)
I also wrote a Perl solution with 128 bytes.
By the way: What about some self-made problems for SHORTEN?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.