C Coding Problem 2011

The Problem

Find the rectangle having the largest area that can be fitted, or lies completely, within a region contained in a given collection of rectangles. The sides of all rectangles are either horizontal or vertical and all of them have integer lengths.

What you must do

We have a file here named "data.txt" containing data in the following format:

First line in the file : An integer representing the number of rectangles

Each of the remaining lines contains four integers (there would be as many lines as there are rectangles):

First integer (xl) : x-coordinate of lower-left corner of rectangle

Second integer (yl) : y-coordinate of lower-left corner of rectangle

Third integer (xu) : x-coordinate of upper-right corner of rectangle

Fourth integer (yu) : y-coordinate of upper-right corner of rectangle

(The file may have data relating to a maximum of 100 rectangles.)

You have to write a programme to perform the following tasks:

i. Read these values from our file and check whether xl < xu and yl < yu for each line.

Otherwise the message "invalid data" must be displayed and the programme must be exited.

ii. If the data are valid, the area of the largest rectangle that can be inscribed in the region contained in the given collection of rectangles must be computed and the result should be displayed in the following format:

Area of largest fitting rectangle : ****

Lower-left corner of largest fitting rectangle : (***, ***)

Upper-right corner of largest fitting rectangle : (***, ***)

Example

See the diagram. The region shown in golden colour is the largest fitting rectangle in the region contained in the four rectangles.

Contents of the file “data.txt”:

4

4 4 8 10

5 2 10 7

6 1 12 6

9 5 13 9

Output:

Area of largest fitting rectangle : 36

Lower-left corner of largest fitting rectangle : (6, 1)

Upper-right corner of largest fitting rectangle : (12, 7)

Additional example 1

Additional example 2

Given rectangular regions

Largest fitting rectangle

Rules and Regulations

1. The code should be prefaced with the following comment lines with the required information:

/*

Name of Participant :

Class in which studying :

Name of College :

Address of College :

:

:

:

Address for communication :

:

:

:

e-mail id :

Contact Phone No (s). :

Operating system and compiler used :

*/

2. The programme should be named name.c where ‘name’ is to be replaced by a string of a maximum of eight characters indicating the name of the participant.

3. The programme should be compilable using standard C compilers (Linux/Windows).No other external header files are allowed.

4. The program code should be submitted as an email attachment to

vidyaccontest2011@gmail.com

not later than 11.00 a.m. on Thursday, 27 October 2011.

5. If there are more than one nearly perfect solution five of the participants will be invited to Vidya Academy campus for making an oral chalk-and-duster presentation of their program.

6. While coming for the presentation, the participants should produce a certificate from the head

of the department to the effect that the participant is a bonafide student of the affiliated college / university teaching department.

7. The following factors will be considered in awarding the prizes:

i. The logical accuracy of the program; whether the program performs the intended tasks without errors.

ii. The programming style: aesthetics, clarity, documentation, maintainability, etc.

iii. The time of receipt of solutions; in case of nearly identical solutions, the one received earlier maybe considered first for a prize.

iv. Oral presentation.

8. The contestants selected for oral presentations will have to make their own arrangements for

travel to Vidya Academy for participating in the oral presentation. The date of the presentation

will be communicated to the selected candidates at the earliest.

9. In all matters related to the contest, the decision of the organizing committee will be final.

End of rules and regulations.

Happy Coding !!!