Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Rectangle Division

By Kryptonyte · Limits 3.5s, 512 MB

You are given a rectangle which is parallel to the coordinate axis. The lower left coordinate is (x,y) and the length of two sides are r and c ( described in figure ). You can easily construct the rectangle by connecting these 4 points { (x,y) , (x+c,y) , (x+c,y+r) , (x,y+r) } in anti-clockwise order.

Fig : A line drawn form (px,py) dividing the rectangle into two equal parts (according to area). Note that, the figure may not be mathematically accurate. It is used just for understanding purposes.

Now, from a given point, you have to draw a line, such that the given line divides the rectangle into two parts of equal area.


The first line of the input file contains T (1<=T<=500000) which denotes the number of test cases. Each of the next lines will contain 6 floating point numbers x , y , r , c , px and py (-1000000<= x , y , r , c , px , py <= 1000000 ) where ( x, y ) is the lower left coordinate of the rectangle, r and c is showed in the figure and ( px,py ) is the point from where we need to draw the line.


Output the intersected points of the drawn line and the sides of the rectangle. Print the points in lexicographical order. No two points in the output will be same. Error less than 10-6 will be ignored.


0 0 6 6 3 -1
3 0
3 6

Note: The dataset of this problem is designed in such a way that there will never be infinitely many solutions.



67% Solution Ratio

NirjhorEarliest, Jul '16

wasimur_01Fastest, 1.2s

bqi343Lightest, 131 kB

wasimur_01Shortest, 852B


Login to submit

Related Contests

Toph uses cookies. By continuing you agree to our Cookie Policy.