ZOJ_1139: Rectangles
Time Limit: 10000 MS Memory Limit: 32 MB 64bit IO Format: %lld[ Submit][ Status][ Web Board]
Description
Write a program that counts the rectangles that are entirely covered by another rectangle.
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
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). An example is given in Figure 1.
Input
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
Output
Source
被一道水题耍了。
大水题,注意看时间有10s,这道题随便怎么暴力都行。
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=100007;
int n;
struct data
{
int minx,miny,maxx,maxy;
}d[N];
bool cmp(data a,data b)
{
if(a.minx==b.minx)
{
return a.miny<b.miny;
}
return a.minx<b.minx;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
int a,b,c,e;
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&e);
d[i].minx=a;
d[i].maxx=b;
d[i].miny=c;
d[i].maxy=e;
}
// sort(d,d+n,cmp);
int sum=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
continue;
if(d[j].minx<=d[i].minx&&d[j].miny<=d[i].miny&&d[j].maxx>=d[i].maxx&&d[j].maxy>=d[i].maxy)
{
sum++;
break;
}
}
}
printf("%d\n",sum);
}
return 0;
}