CSP201409-2: drawing, csp201409-2 drawing

Source: Internet
Author: User

CSP201409-2: drawing, csp201409-2 drawing

Introduction:CSP (http://www.cspro.org/lead/application/ccf/login.jsp) is a "Computer vocational qualification certification" examination initiated by CCF, perform capability certification for professionals in computer software development, software testing, information management, and other fields. The subjects of certification are those who are engaged in or will be engaged in IT professional technical and technical management personnel, as well as review subjects for university recruitment and postgraduate students.

 

  • Problem description

On a paper that defines the Cartesian coordinate system, draw a rectangle from (x1, y1) to (x2, y2) to convert the abscissa from x1 to x2, colors the area from y1 to y2.

An example of drawing two rectangles is given. The first rectangle is (1, 1) to (4, 4), expressed in green and purple. The second rectangle is (2, 3) to (6, 5), represented in blue and purple. In the figure, a total of 15 units of area are colored, and the purple part is painted twice, but the area is calculated only once. In the actual coloring process, all rectangles are painted in a uniform color. Different colors are shown in the figure for convenience.

Show all the rectangles to be painted. How many units of area are painted.

  • Input Format

The first line of the input contains an integer n, indicating the number of rectangles to be drawn.

In the next n rows, each line has four non-negative integers, indicating the abscissa and ordinate in the lower left corner of the rectangle to be drawn, and the abscissa and ordinate in the upper right corner.

  • Output Format

The output is an integer indicating the number of units in which the area is colored.

  • Sample Input

    2

    1 1 4 4

    2 3 6 5

  • Sample output

    15

  • Scale and conventions of evaluation cases

    1 <= n <= 100, 0 <= X and Y <=.

 

  • Source code

# Include <stdio. h>

# Include <stdlib. h>

# Include <memory. h>

 

# Define N 101

 

// Coordinates

Struct pos {

Int x1;

Int y1;

Int x2;

Int y2;

};

 

Int main (void)

{

Int n; // Number of rectangles

Int area = 0;

Int canvas [N] [N] = {0}; // all vertices in the coordinate system. 0 indicates that they are not colored, and 1 indicates that they have been colored.

Scanf ("% d", & n );

Pos * pPst = (pos *) malloc (sizeof (pos) * n );

Memset (pPst, 0, sizeof (pos) * n );

For (int I = 0; I <n; I ++)

{

Scanf ("% d", & (pPst [I]. x1 ));

Scanf ("% d", & (pPst [I]. y1 ));

Scanf ("% d", & (pPst [I]. x2 ));

Scanf ("% d", & (pPst [I]. y2 ));

}

For (int I = 0; I <n; I ++)

{

For (int m = pPst [I]. x1; m <pPst [I]. x2; m ++)

{

For (int n = pPst [I]. y1; n <pPst [I]. y2; n ++)

{

If (canvas [m] [n] = 0)

{

Area + = 1;

Canvas [m] [n] = 1;

}

}

}

}

Printf ("% d \ n", area );

Free (pPst );

Return 0;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.