ZOJ1139 POJ1468 Rectangles【水题】

Rectangles
Time Limit: 5000MS Memory Limit: 10000K
Total Submissions: 3519 Accepted: 1793

Description

A specialist in VLSI design testing must decide if there are some components that cover each other for a given design. A component is represented as a rectangle. Assume that each rectangle is rectilinearly oriented (sides parallel to the x and y axis), so that the representation of a rectangle consists of its minimum and maximum x and y coordinates.
Write a program that counts the rectangles that are entirely covered by another rectangle.

Input

The input contains the text description of several sets of rectangles. The specification of a set consists of the number of rectangles in the set and the list of rectangles given by the minimum and maximum x and y coordinates separated by white spaces, in the format:

nr_rectangles
xmin1 xmax1 ymin1 ymax1
xmin2 xmax2 ymin2 ymax2
...
xminn xmaxn yminn ymaxn

For each set,there will be less than 5000 rectangles.

Output

The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the number of rectangles that are covered).

Sample Input

3
100 101 100 101
0 3 0 101
20 40 10 400
4
10 20 10 20
10 20 10 20
10 20 10 20
10 20 10 20

Sample Output

0
4

Source

Southeastern Europe 2000

问题链接ZOJ1139 POJ1468 Rectangles
问题简述:(略)
问题分析
    判断矩形是否重叠,简单题不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* ZOJ1139 POJ1468 Rectangles */

#include <stdio.h>

#define N 10000
struct {
    int xmin, ymin, xmax, ymax;
} a[N];

int main(void)
{
    int n, i, j;
    while(scanf("%d", &n) != EOF) {
        for(i = 0; i < n; i++)
            scanf("%d%d%d%d", &a[i].xmin, &a[i].xmax, &a[i].ymin, &a[i].ymax);
        int cnt = 0;
        for(i = 0; i < n; i++)
            for(j = 0; j < n; j++)
                if(i != j && a[i].xmin >= a[j].xmin &&
                        a[i].xmax <= a[j].xmax &&
                        a[i].ymin >= a[j].ymin &&
                        a[i].ymax <= a[j].ymax) {
                    cnt++;
                    break;
                }
        printf("%d\n", cnt);
    }

    return 0;
}
上一篇:6-1 设计一个矩形类Rectangle (10分)


下一篇:雷林鹏分享:C# 基本语法