CCF CSP Brush Question Record 5-201409-2 Drawing (java)

Question number: 201409-2
Question name: Drawing
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:

Problem Description

  Drawing a rectangle from (x1, y1) to (x2, y2) on a piece of paper that defines a rectangular coordinate system means to color the area between the abscissa range from x1 to x2 and the ordinate range from y1 to y2 .
  The following figure shows an example of drawing two rectangles. The first rectangle is (1,1) to (4, 4), represented in green and purple. The second rectangle is (2, 3) to (6, 5), represented in blue and purple. In the picture, a total of 15 units of area are painted, of which the purple part is painted twice, but only once when calculating the area. In the actual coloring process, all rectangles are painted in a uniform color, and the different colors shown in the figure are only for convenience of illustration.

  Given all the rectangles to be drawn, how many units of the area are colored.

Input format

  The first line of input contains an integer n, which represents the number of rectangles to be drawn.
  The next n rows, each with 4 non-negative integers, represent the abscissa and ordinate of the lower left corner, and the abscissa and ordinate of the upper right corner of the rectangle to be drawn.

Output format

  Output an integer, indicating how many units of the area are colored.

Sample input

2
1 1 4 4
2 3 6 5

Sample output

15

Evaluation use case scale and conventions

  1<=n<=100, 0<=abscissa, ordinate<=100.

 

import java.util.Scanner;
public class 画图201409_2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int len=sc.nextInt();
		int[][] a=new int[101][101];
		int[] area=new int[4*len+1];
		for(int i=1;i<=4*len;i++){
			area[i]=sc.nextInt();
		}
		for(int i=0;i<len;i++){
			for(int j=area[4*i+1];j<area[4*i+3];j++){
				for(int k=area[4*i+2];k<area[4*i+4];k++){
					a[j][k]=1;
				}
			}
		}
		int sum=0;
		for(int i=0;i<100;i++){
			for(int j=0;j<100;j++){
				if(a[i][j]!=0){
					sum+=1;
				}
			}
		}
		System.out.println(sum);
	}

}

 

Guess you like

Origin blog.csdn.net/m0_37483148/article/details/108270417