Infinite Game

flash_7 The Tough Summer Spar 201...
Limits 1s, 512 MB

One day Oditi and her two brothers Sam and Ron were feeling bored as their summer vacation was almost getting over. Then suddenly they planned for an interesting game. There was an infinite grid land and the game was about having as much area of it as they can take. But there are some rules.

Oditi is at co-ordinate (0,0)(0, 0) and for a given R, she can only reach the land which are not more than R distance from her own position. Sam is at position (x1,y)(x1, -y) and Ron is at (x2,y)(x2, -y). Sam wants to reach at (x1,y)(x1, y) and Ron wants to reach at (x2,y)(x2, y). So Sam will start running from (x1,y)(x1, -y) and Ron will start running from (x2,y)(x2, -y) through a straight line until they reach their destination. They will be able to reach the land that lie between their path.

But they also have another little cousin named Tom. Tom will not play the game but he also wants to get some part of the land. Otherwise he won’t let them play.

As Oditi is the eldest, she made the final decision. Tom will get the area which is reachable by both Oditi and her brothers (Sam and Ron). And excluding the area that Tom gets, Oditi will get the rest of the area which are reachable from her. Sam and Ron will both get half of the area that are reachable from them excluding the area Tom gets.

Now you have to calculate the area which will be taken by Oditi, Sam, Ron and Tom.

The picture illustrates the first case of sample input. Here Tom gets the intersected lined area, Sam and Ron both gets the half of the dotted area. And Oditi gets the blank area inside the circle.


The first line contains an integer number TT (1T1031 ≤ T ≤ 10^3) which is the number of test cases. For each test case, there will be a single line which contains 4 decimal numbers RR, x1x1, x2x2 (1x1,x2,R1031 ≤ x1, x2, R ≤ 10^3) and yy (Ry103R ≤ y ≤ 10^3). yy is always greater than RR and x1x2x1 \ne x2.


For each test case, print four space separated values, the area of the lands Oditi, Sam, Ron and Tom will get. Always print 3 digits after the decimal point.


6 2 5 8
6 2 5 10
10 6 11 15
5 3 5 8
84.598 9.750 9.750 28.499
84.598 15.750 15.750 28.499
269.430 52.635 52.635 44.730
67.357 10.409 10.409 11.182


Login to submit.


82% Solution Ratio
sahedsohelEarliest, Jul '16
Tarik.amtolyFastest, 0.0s
nightfury1204Lightest, 131 kB
alvee9Shortest, 560B
Toph uses cookies. By continuing you agree to our Cookie Policy.