zoukankan      html  css  js  c++  java
  • sdut 2401 最大矩阵面积 夜

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2401

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;

    const int N=1010;
    struct node
    {
        int x,y;
    }mem[N];
    bool cmp(node a,node b)
    {
        if(a.x==b.x)
        return a.y<b.y;
        return a.x<b.x;
    }
    bool cmp1(node a,node b)
    {
        if(a.y==b.y)
        return a.x<b.x;
        return a.y<b.y;
    }
    int main()
    {
        //freopen("data.txt","r",stdin);
        int T;
        int L,W,Point;
        cin>>T;
        while(T--)
        {
            cin>>L>>W;
            mem[0].x=0;mem[0].y=0;
            mem[1].x=0;mem[1].y=W;
            mem[2].x=L;mem[2].y=0;
            mem[3].x=L;mem[3].y=W;
            cin>>Point;
            for(int i=4;i<4+Point;++i)
            {
               cin>>mem[i].x>>mem[i].y;
            }
            sort(mem,mem+Point+4,cmp);
            int ans=0;
            for(int i=0;i<Point+4;++i)
            {
                for(int j=i+1,low=0,high=W,Maxl=L-mem[i].x;j<Point+4;++j)
                {
                    if(mem[j].y<=high&&mem[j].y>=low)
                    {
                        ans=max(ans,(high-low)*(mem[j].x-mem[i].x));
                        if(mem[j].y==mem[i].y)
                        break;
                        if(mem[j].y<mem[i].y)
                        low=mem[j].y;
                        else
                        high=mem[j].y;
                        if((high-low)*Maxl<=ans)
                        break;
                    }
                }
            }
            sort(mem,mem+Point+4,cmp1);
            for(int i=0;i<Point+4;++i)
            {
                for(int j=i+1,low=0,high=L,Maxl=W-mem[i].y;j<Point+4;++j)
                {
                    if(mem[j].x<=high&&mem[j].x>=low)
                    {
                        ans=max(ans,(high-low)*(mem[j].y-mem[i].y));
                        if(mem[j].x==mem[i].x)
                        break;
                        if(mem[j].x<mem[i].x)
                        low=mem[j].x;
                        else
                        high=mem[j].x;
                        if((high-low)*Maxl<=ans)
                        break;
                    }
                }
            }
            cout<<ans<<endl;
        }
        return 0;

    }

  • 相关阅读:
    第一篇日志
    Spring mvc 4系列教程(三)—— Spring4.X的新特性
    Spring mvc 4系列教程(二)——依赖管理(Dependency Management)和命名规范(Naming Conventions)
    Spring mvc 4系列教程(一)
    【管理心得之三十六】《黄帝内经》中的一句话
    【管理心得之三十五】好习惯也能惹“骂名”
    【管理心得之三十四】“禅宗境界”的员工
    【管理心得之三十三】管理者的“眉头”
    【管理心得之三十二】PMP杂谈---------爱情必胜术
    【管理心得之三十一】我的位置
  • 原文地址:https://www.cnblogs.com/liulangye/p/2467012.html
Copyright © 2011-2022 走看看