【Luogu】P1578奶牛浴场(DP,枚举)

  题目链接

  枚举极大子矩形。详情请见本题题解:I_AM_HelloWord

  代码如下

  

#include<cstdio>
#include<cctype>
#include<algorithm>
inline long long read(){
    long long num=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-')    f=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        num=num*10+ch-'0';
        ch=getchar();
    }
    return num*f;
}

struct Que{
    int y,x;
    bool operator <(const Que a)const{
        return y<a.y;
    }
}point[100000];

int ans;

int main(){
    int L=read(),W=read(),n=read();
    point[1]=(Que){0,0};
    point[2]=(Que){0,L};
    point[3]=(Que){W,0};
    point[4]=(Que){W,L};
    for(int i=1;i<=n;++i)    point[i+4]=(Que){read(),read()};
    n+=4;
    std::sort(point+1,point+n+1);
    for(int i=1;i<=n;++i){
        int l=point[i].y,r=L,u=0,d=W;
        for(int j=i+1;j<=n;++j){
            r=point[j].y;
            ans=std::max(ans,(r-l)*(d-u));
            if(point[j].x==point[i].x)    break;
            else if(point[j].x>point[i].x)    d=std::min(d,point[j].x);
            else u=std::max(u,point[j].x);
            r=L;
        }
    }
    printf("%d",ans);
    return 0;
}

 

转载于:https://www.cnblogs.com/cellular-automaton/p/7574865.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值