zoukankan      html  css  js  c++  java
  • 【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;
    }
  • 相关阅读:
    第0次作业
    第4次作业
    第3次作业
    第2次作业
    C#浮点数保留位数
    第0次作业
    软件工程第4次作业
    软件工程第3次作业
    软件工程第2次作业
    软件工程第1次作业
  • 原文地址:https://www.cnblogs.com/cellular-automaton/p/7574865.html
Copyright © 2011-2022 走看看