HDOJ 2478 Slides
来源:互联网 发布:淘宝开店基础知识 编辑:程序博客网 时间:2024/05/21 22:36
维护次大和最大的左下角和右上角的坐标,再枚举抽出哪一个矩阵。。。
Slides
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 923 Accepted Submission(s): 311
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
220 0 2 21 1 2 230 0 2 21 0 3 21 1 3 3
Sample Output
42
Source
2008 Asia Regional Chengdu
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int INF=0x3f3f3f3f;int n;int Lx1,Lx2,Ly1,Ly2,Rx1,Rx2,Ry1,Ry2;struct Point{int x,y;}p[2][120000];int main(){int T_T;scanf("%d",&T_T);while(T_T--){scanf("%d",&n);Lx1=Lx2=Ly1=Ly2=-INF;Rx1=Rx2=Ry1=Ry2=INF;for(int i=0;i<n;i++){int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);p[0][i]=(Point){a,b};p[1][i]=(Point){c,d};if(a>Lx1){Lx2=Lx1; Lx1=a;}else if(a>Lx2){Lx2=a;}if(b>Ly1){Ly2=Ly1; Ly1=b;}else if(b>Ly2){Ly2=b;}if(c<Rx1){Rx2=Rx1; Rx1=c;}else if(c<Rx2){Rx2=c;}if(d<Ry1){Ry2=Ry1; Ry1=d;}else if(d<Ry2){Ry2=d;}}int ans=0;if(n==1) {printf("%d\n",ans);continue;}for(int i=0;i<n;i++){int LX,LY,RX,RY;if(p[0][i].x==Lx1) LX=Lx2;else LX=Lx1;if(p[0][i].y==Ly1) LY=Ly2;else LY=Ly1;if(p[1][i].x==Rx1) RX=Rx2;else RX=Rx1;if(p[1][i].y==Ry1) RY=Ry2;else RY=Ry1;if(RY>LY&&RX>LX) ans=max(ans,(RY-LY)*(RX-LX));}printf("%d\n",ans);}return 0;}
1 0
- HDOJ 2478 Slides
- HDU 2478 Slides(瞎搞,预处理)
- Lecture Slides
- Hbase slides
- hdu2478 Slides
- HDU 2478 Slides(n个矩形中n-1个矩形相交最大面积)
- slides - Sun开源Java
- Sicily 1799. Slides
- CTS training slides
- POJ-1486-Sorting Slides
- poj1486 - Sorting Slides
- poj 1486 Sorting Slides
- POJ1486:Sorting Slides
- Slides中插入脚注
- POJ 1486 Sorting Slides
- POJ-1486-Sorting Slides
- 开源slides工具
- Sicily 1913. Slides
- 渣渣算法初步回顾---树状数组
- 腾讯2014校园实习生招聘
- C - Red and Black
- 老程序员的下场 程序员老了该怎么办?
- 表达式求值算法
- HDOJ 2478 Slides
- 洗心革面重新开始
- hdu2639-01背包(第k大背包问题)
- 十分钟让你明白Objective-C的语法(和Java、C++的对比)
- 反射的使用---创建对象
- 从虚拟机硬盘文件.vmdk恢复数据
- 数据库操作集
- Android之ContentProvider总结
- 《UNIX环境高级编程》 —— I/O