• bzoj 5085: 最大——结论题qwq


    Description

    给你一个n×m的矩形,要你找一个子矩形,价值为左上角左下角右上角右下角这四个数的最小值,要你最大化矩形
    的价值。

    Input

    第一行两个数n,m,接下来n行每行m个数,用来描述矩形
    n, m ≤ 1000

    Output

    输出一个数表示答案

    Sample Input

    2 2
    1 2
    3 4

    Sample Output

    1
    ———————————————————————————
    这道题ljk猜了个结论 答案一定在那最大的4*n个点中 所以用一下STL的nth_element
    然后枚举一下对角线 复杂度n^2就可以辣23333
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    using std::swap;
    using std::min;
    using std::max;
    const int M=2e3+7;
    char buf[M*M*11],*ptr=buf-1;
    int read(){
        int ans=0,f=1,c=*++ptr;
        while(c<'0'||c>'9'){if(c=='-') f=-1; c=*++ptr;}
        while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=*++ptr;}
        return ans*f;
    }
    int n,m,k,s[M][M],cnt,sum,ans;
    struct pos{
        int x,y,w;
        bool operator <(const pos& h)const{return w>h.w;}
    }q[M*M];
    int main(){
        fread(buf,1,sizeof(buf),stdin);
        n=read(); m=read(); k=std::min(4*n,n*m);
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) 
        s[i][j]=read(),q[cnt++]=(pos){i,j,s[i][j]};
        std::nth_element(q,q+k,q+cnt);
        for(int i=0;i<k;i++){
            for(int j=0;j<i;j++)if(q[i].x!=q[j].x&&q[i].y!=q[j].y){
                sum=min(s[q[i].x][q[i].y],s[q[j].x][q[j].y]);
                sum=min(sum,s[q[i].x][q[j].y]);
                sum=min(sum,s[q[j].x][q[i].y]);
                ans=max(ans,sum);
            }
        }printf("%d
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    HTML5文件上传前本地预览
    sql(2) DISTINCT
    sql (1)
    delphi 第4课
    delphi 第3课
    Delphi 第2课
    delphi 用户可以点击格式修改进行模板修改
    delphi 流程单打印
    Delphi 第一课
    【BZOJ4530】[Bjoi2014]大融合 LCT维护子树信息
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7751559.html
Copyright © 2020-2023  润新知