luogu1578 奶牛浴场 枚举点最大子矩阵

建议看看王知昆dalao的论文,讲得很好

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int l, w, n, ans=0, sh, xi, ma;
struct Node{
    int x, y;
}nd[5105];
bool cmp1(Node u, Node v){
    return u.y<v.y;
}
bool cmp2(Node u, Node v){
    if(u.x==v.x)    return u.y<v.y;
    return u.x<v.x;
}
int main(){
    cin>>l>>w>>n;
    for(int i=1; i<=n; i++)
        scanf("%d %d", &nd[i].x, &nd[i].y);
    nd[++n] = (Node){0, 0};
    nd[++n] = (Node){l, 0};
    nd[++n] = (Node){0, w};
    nd[++n] = (Node){l, w};
    sort(nd+1, nd+1+n, cmp1);
    for(int i=1; i<n; i++)
        ans = max(ans, (nd[i+1].y-nd[i].y)*l);
    sort(nd+1, nd+1+n, cmp2);
    for(int i=1; i<=n; i++){
        sh = w; xi = 0; ma = l - nd[i].x;
        for(int j=i+1; j<=n; j++)
            if(nd[j].y<=sh && nd[j].y>=xi){
                if(ma*(sh-xi)<=ans) break;
                ans = max(ans, (nd[j].x-nd[i].x)*(sh-xi));
                if(nd[j].y==nd[i].y)    break;
                else if(nd[j].y>nd[i].y)    sh = nd[j].y;
                else    xi = nd[j].y;
            }
        sh = w; xi = 0; ma = nd[i].x;
        for(int j=i-1; j>=1; j--){
            if(nd[j].y<=sh && nd[j].y>=xi){
                if(ma*(sh-xi)<=ans) break;
                ans = max(ans, (nd[i].x-nd[j].x)*(sh-xi));
                if(nd[j].y==nd[i].y)    break;
                else if(nd[j].y>nd[i].y)    sh = nd[j].y;
                else    xi = nd[j].y;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/poorpool/p/8031732.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值