您的位置:首页 > 其它

【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<=5000

1<=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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: