HDU 2478 Slides(瞎搞,預處理)
題目的大意就是:給你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.
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;
}
相關文章
- HDU 4925 Apple Tree (瞎搞)APP
- HDU 4455 Substrings(預處理+dp)
- HDU 4923 Room and Moor(瞎搞題)OOM
- HDU 5317 RGCDQ (素因子分解+預處理)GC
- HDU3944 DP? (LUCAS定理+階乘預處理)
- HDU 5439 Aggregated Counting(找規律+預處理)
- HDU4675 GCD of Sequence(預處理階乘逆元+推公式)GC公式
- 影像預處理
- 預處理指令
- 預處理命令
- HDU 4542 小明系列故事——未知剩餘系 (DFS 反素數 篩子預處理)
- hdu4288 離線處理線段樹
- hdu 1753 Java 高精度處理 大明A+BJava
- 資料預處理
- 影像預處理方法
- HDU5139 Formula (找規律+離線處理)ORM
- HDU5200 Trees (離線處理)
- 資料預處理 demo
- poj 2478 尤拉函式函式
- hdu5435 數位dp(大數的處理)
- 【scikit-learn基礎】--『預處理』之 缺失值處理
- nlp 中文資料預處理
- 機器學習一:資料預處理機器學習
- 文字檢測預處理地址
- 程式環境和預處理
- 影像預處理包括哪些東東?
- split用法與影像預處理
- 特徵工程之特徵預處理特徵工程
- 資料預處理規則
- 資料預處理的形式
- 預處理技術文獻
- ZOJ First Digit(瞎搞)Git
- 第五篇:資料預處理(二) - 異常值處理
- 第四篇:資料預處理(一) - 缺失值處理
- SPM12之fMRI批次預處理——NII檔案處理
- C語言的本質(21)——預處理之三:其它預處理特性及總結C語言
- 資料預處理方法彙總
- yai 請求預處理指令碼AI指令碼