# 1468 Rectangles

Rectangles
 Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 1187 Accepted: 586

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

Sample Output

Source
Southeastern Europe 2000

*******************************************************************************

***********************************************************************************

Source Code
////现根据面积，选出面积最大的，并插入排序 并保存原始的数据下标！！！！再搜索一下符合条件的

#include <iostream>
using namespace std;

struct Rectangle
{
int minx;
int maxx;
int miny;
int maxy;
};

int main()
{
int Area[5000],Area1[5000],a[5000];
Rectangle Rec[5000];
int i ,j ,temp ;
int num, Index ,sum;
while(scanf("%d",&num )!=EOF )
{
for(i=0; i<num; i++)
{
scanf("%d %d %d %d", &Rec[i].minx, &Rec[i].maxx, &Rec[i].miny, &Rec[i].maxy );
Area[i] = ( Rec[i].maxx - Rec[i].minx ) *( Rec[i].maxy-Rec[i].miny);
Area1[i] =Area[i];
}

for(i=0;i<num-1;i++)
{
int   min=i;
for(j = i+1; j < num; j ++)
if( Area1[j] < Area1[min])
min = j;
temp = Area1[min];
Area1[min] = Area1[i];
Area1[i] = temp;
}
for(i = 0; i < num; i ++)
for(j=0 ; j < num; j ++)
if(Area1[i] == Area[j])
{
Area[j]=0;
a[i]=j;
break;
}
for(sum=0,j=0;j<num-1;j++)
for(i=j+1;i<num;i++)
if(Rec[a[j]].maxx<=Rec[a[i]].maxx&&Rec[a[j]].minx>=Rec[a[i]].minx
&&Rec[a[j]].maxy<=Rec[a[i]].maxy&&Rec[a[j]].miny>=Rec[a[i]].miny )
{
sum++;
break;
}
for(i=0;i<num-1;i++)
if(Rec[i].maxx==Rec[num-1].maxx && Rec[i].minx==Rec[num-1].minx
&&Rec[i].maxy==Rec[num-1].maxy&&Rec[i].miny==Rec[num-1].miny)
{
sum+=1;
break;
}

printf("%d/n",sum);
}
return 0;
}


0
4

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
• 本文已收录于以下专栏：

举报原因： 您举报文章：1468 Rectangles 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)