【WC2002】奶牛浴场
2016-01-17 15:02
267 查看
描述
由于John建造了牛场围栏,激起了奶牛的愤怒,奶牛的产奶量急剧减少。为了讨好奶牛,John决定在牛场中建造一个大型浴场。但是John的奶牛有一个奇怪的习惯,每头奶牛都必须在牛场中的一个固定的位置产奶,而奶牛显然不能在浴场中产奶,于是,John希望所建造的浴场不覆盖这些产奶点。这回,他又要求助于Clevow了。你还能帮助Clevow吗?John的牛场和规划的浴场都是矩形。浴场要完全位于牛场之内,并且浴场的轮廓要与牛场的轮廓平行或者重合。浴场不能覆盖任何产奶点,但是产奶点可以位于浴场的轮廓上。
Clevow当然希望浴场的面积尽可能大了,所以你的任务就是帮她计算浴场的最大面积。
格式
输入格式
输入文件的第一行包含两个整数L和W,分别表示牛场的长和宽。文件的第二行包含一个整数n,表示产奶点的数量。以下n行每行包含两个整数x和y,表示一个产奶点的坐标。所有产奶点都位于牛场内,即:0<=x<=L,0<=y<=W。输出格式
输出文件仅一行,包含一个整数S,表示浴场的最大面积。
样例1
样例输入1[复制]
10 10 4 1 1 9 1 1 9 9 9
样例输出1[复制]
80
限制
各个测试点1s
提示
0<=n<=50001<=L,W<=30000
来源
Winter Camp 2002【题解】
悬线法算法1模板题
具体的过程就不说了,说几种特殊的情况
1、当前点在边界之外:直接计算当前的极大子矩形的值,不改变上线边界
2、当前点和左边界的点行相同:更新上下边界时哪个近更新哪个
3、在整个矩形的四个顶点处各放一个点
【代码】
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> using namespace std; struct hp{ int x,y; }temp[5050]; int L,W,x,y,n,ans,tot,up,down; int cmp(hp a,hp b){ return a.x<b.x; } int cmp1(hp a,hp b){ return a.y<b.y; } int cmp2(hp a,hp b){ return a.y>b.y; } int main(){ scanf("%d%d",&L,&W); scanf("%d",&n); for (int i=1;i<=n;++i) scanf("%d%d",&x,&y),temp[++tot].x=x,temp[tot].y=y; temp[++tot].x=0,temp[tot].y=0; temp[++tot].x=0,temp[tot].y=W; temp[++tot].x=L,temp[tot].y=0; temp[++tot].x=L,temp[tot].y=W; sort(temp+1,temp+tot+1,cmp); for (int i=2;i<=tot;++i) ans=max(ans,(temp[i].x-temp[i-1].x)*W); sort(temp+1,temp+tot+1,cmp1); for (int i=1;i<tot;++i){ up=0; down=L; for (int j=i+1;j<=tot;++j) if (temp[j].x>=up&&temp[j].x<=down){ ans=max(ans,(temp[j].y-temp[i].y)*(down-up)); if (temp[j].x<temp[i].x) up=temp[j].x; else if (temp[j].x>temp[i].x) down=temp[j].x; else if (temp[j].x==temp[i].x){ if (temp[j].x-up<down-temp[j].x) up=temp[j].x; else down=temp[j].x; } } else ans=max(ans,(temp[j].y-temp[i].y)*(down-up)); } sort(temp+1,temp+tot+1,cmp2); for (int i=1;i<tot;++i){ up=0; down=L; for (int j=i+1;j<=tot;++j) if (temp[j].x>=up&&temp[j].x<=down){ ans=max(ans,(temp[i].y-temp[j].y)*(down-up)); if (temp[j].x<temp[i].x) up=temp[j].x; else if (temp[j].x>temp[i].x) down=temp[j].x; else if (temp[j].x==temp[i].x){ if (temp[j].x-up<down-temp[j].x) up=temp[j].x; else down=temp[j].x; } } else ans=max(ans,(temp[i].y-temp[j].y)*(down-up)); } printf("%d",ans); }
相关文章推荐
- Android中下拉刷新和加载更多的实现方式
- hadoop基础:第三部分 分布式文件系统
- UVA 18451 阅读题
- HDU4452Running Rabbits(模拟)
- ejb injection
- 注册时手机验证用户
- Python+django实现文件下载
- VS添加环境变量和自定义宏
- PASSION之XML详解
- [从头学数学] 第50节 复式统计表
- CSS 布局模型
- CSS 盒模型
- jQuery中的DOM操作(一)
- 生产环境提升rman备份速度----启动块跟踪
- 【转】零基础写Java知乎爬虫之进阶篇
- CDateTimeUI类源码分析
- codevs1966乘法游戏
- CodeForces 527A Playing with Paper
- 使用pure-ftpd实现ftp功能
- 2、Reactjs中的属性(this.props)