南邮 OJ 1608 Slides

来源:互联网 发布:windows dream scence 编辑:程序博客网 时间:2024/06/11 15:23

Slides

时间限制(普通/Java) : 3000 MS/ 9000 MS          运行内存限制 : 65536 KByte
总提交 : 29            测试通过 : 11 

比赛描述

There are N slides lying on the table. Each of them is transparent and formed as a rectangle. In a traditional problem, one may have to calculate the intersecting area of these N slides. The definition of intersection area is such area which belongs to all of the slides.

But this time I want to take out some one of the N slides, so that the intersecting area of the left N - 1 slides should be maximal. Tell me the maximum answer.




输入

The first line of the input contains a single integer T , the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer N (1 ≤ N ≤ 100) , the number of rectangles. Followed by N lines, each line contains four integers x1 , y1 , x2 , y2 (- 10000 ≤ x1 < x2 ≤ 10000,-10000  y1 < y2  10000) , pair (x1, y1) gives out the bottom-left corner and pair (x2, y2) gives out the top-right corner of the rectangle.


输出

There should be one line per test case containing the maximum intersecting area of corresponding N - 1 slides.

样例输入

2
2
0 0 2 2
1 1 2 2
3
0 0 2 2
1 0 3 2
1 1 3 3

样例输出

4
2

题目来源

ICPC






#include<iostream>#define N 100using namespace std;__int64 x1[N];__int64 y1[N];__int64 x2[N];__int64 y2[N];int main(){//freopen("test.txt","r",stdin);//WA1__int64 t,n,i,j,maxX1,maxY1,minX2,minY2,area,maxArea;scanf("%I64d",&t);while(t--){scanf("%I64d",&n);for(i=0; i<n; i++){scanf("%I64d%I64d%I64d%I64d",x1+i,y1+i,x2+i,y2+i);}maxArea = 0;for(i=0;i<n;i++){maxX1 = maxY1 = INT_MIN;minX2 = minY2 = INT_MAX;for(j=0;j<n;j++){if(j==i){continue;}if(x1[j] > maxX1){maxX1 = x1[j];}if(y1[j] > maxY1){maxY1 = y1[j];}if(x2[j] < minX2){minX2 = x2[j];}if(y2[j] < minY2){minY2 = y2[j];}}if(minY2>maxY1 && minX2>maxX1){area = (minY2-maxY1)*(minX2-maxX1);if(area > maxArea){maxArea = area;}}}printf("%I64d\n",maxArea);}}


0 0
原创粉丝点击