题目的大意就是:给你n对点,第一个点表示正方形左上角的点,第二个点表示正方形右上角的点。然后从这n个点中,取走一个点,之后求出这n-1个正方形的交集所组成的矩形的面积的最大。
思路是:给出n个点之后相交的那个矩形的四个点是可以确定的。然后枚举去掉这n个点,然后判断一下去掉这个点之后这个交集的四个点是否在这个正方形上。如果在相交的矩形的范围就扩大到第二小的点上了啊。一次判断四个点,最后求出面积。
Slides
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 928 Accepted Submission(s): 312
Problem Description 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.
Input 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 <= 100000), 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.
Output There should be one line per test case containing the maximum intersecting area of corresponding N-1 slides.
Sample Input
2
2
0 0 2 2
1 1 2 2
3
0 0 2 2
1 0 3 2
1 1 3 3
Sample Output
4
2
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
const int maxn = 100010;
using namespace std;
int x1[maxn], Y1[maxn], x2[maxn], y2[maxn];
int main()
{
int T, n;
while(~scanf("%d",&T))
{
while(T--)
{
int l1 = -INF;
int l2 = -INF;
int r1 = INF;
int r2 = INF;
int ll1 = -INF;
int ll2 = -INF;
int rr1 = INF;
int rr2 = INF;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%d %d %d %d",&x1[i], &Y1[i], &x2[i], &y2[i]);
if(l1 < x1[i])
{
l2 = l1;
l1 = x1[i];
}
else if(l2 < x1[i])
l2 = x1[i];
if(r1 > x2[i])
{
r2 = r1;
r1 = x2[i];
}
else if(r2 > x2[i])
r2 = x2[i];
if(ll1 < Y1[i])
{
ll2 = ll1;
ll1 = Y1[i];
}
else if(ll2 < Y1[i])
ll2 = Y1[i];
if(rr1 > y2[i])
{
rr2 = rr1;
rr1 = y2[i];
}
else if(rr2 > y2[i])
rr2 = y2[i];
}
if(n == 1)
{
printf("0\n");
continue;
}
int xx1, xx2, yy1, yy2;
int cnt = 0;
for(int i = 0; i < n; i++)
{
if(x1[i] == l1)
xx1 = l2;
else
xx1 = l1;
if(x2[i] == r1)
xx2 = r2;
else
xx2 = r1;
if(Y1[i] == ll1)
yy1 = ll2;
else
yy1 = ll1;
if(y2[i] == rr1)
yy2 = rr2;
else
yy2 = rr1;
if(xx1 < xx2 && yy1 < yy2)
cnt = max(cnt, ((xx2-xx1)*(yy2-yy1)));
}
printf("%d\n",cnt);
}
}
return 0;
}