(I know... might be a bad one... but thats how we are.... atleast the two of us blogging here...)
The code jam is up... and I see 2 good questions.... I thought all this while that it would be tough.... lets see how it shapes up!
With 15 minutes to solve them, here are the questions.....
Problem 1:
Given the Top-Right (x1,y1) and Bottom-Left (x2,y2) integer co-ordinates of two Rectangles parallel to the X-Y axes, Write a program to find the area of the rectangle formed by the intersection of the two given Rectangles.
Note:
- The co-ordinate system is such that x increases from left to right, and y increases from bottom to top.
- If the rectangles are non-intersecting, then the area is 0.
- If one rectangle is contained inside another, the area of intersection is the area of the smaller rectangle. Else If the two rectangles share a common edge and have no common area, then also the area (output of your program) is 0.
Input Definition:
- On the first line, x1 y1 x2 y2 for the first rectangle
- On the second line, x1 y1 x2 y2 for the second triangle
Output:
- A single value representing the area of the intersection of the given rectangles
Problem 2:
Given an NxM Grid (N rows and M columns) find the number of rectangles that are there on the grid. Assume the grid to be having a coordinate system with bottom-left corner as the origin (0,0). Write program to Output the coordinates of the left-top and right bottom vertices of each of the rectangles in a sequential order.
Input :-
value of N and M on the same line, in a file or on the console.
e.g. 8 8
Output :-
(x11, y11) (x12, y12) |--> top left and bottom right vertex of the first rectangle
(x21, y21) (x22, y22)
:
:
(xr1, yr1) (xr2, yr2) | where r is the no. of rows of output (total no. of rectangles).
e.g. for input 8 8 output would be:-
1296
(0, 0) (1, 1)
(0, 0) (1, 2)
(0, 0) (1, 3)
:
(1, 1) (8, 8)
:
(M, N) (M+1, N+1) or (8, 8) (9, 9) | total 1296 rows of coordinates.
No comments:
Post a Comment