zoukankan      html  css  js  c++  java
  • 网格中的极大子矩形的另类解法

    http://www.doc88.com/p-9042008501060.html

    论文说的很清楚

    Cricket FieldUVALive - 2689 

    附送代码

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<queue>
    #include<map>
    #include<set>
    #include<list>
    #include<ctime>
    #include<ctype.h>
    #include<bitset>
    #include<algorithm>
    #include<numeric> //accumulate
    #define endl "
    "
    #define fi first
    #define se second
    #define FOR(i,s,t) for(int i=(s);i<=(t);++i)
    #define mem(a,b) memset(a,b,sizeof(a))
    using namespace std;
    const int maxn=100000+10;
    int n,w,h;
    struct Node
    {
        int x,y;
    };
    Node p[maxn];
    int main()
    {
    
        //cout<<mid(25,5)<<endl;
        //cin.tie(0);
        //cout.tie(0);
        //ios_base::sync_with_stdio(false);
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int T;
        cin>>T;
        while(T--)
        {
            cin>>n>>w>>h;
            for(int i=0; i<n; i++)
            {
                int x,y;
                cin>>x>>y;
                p[i]= {x,y};
            }
            p[n++]= {0,0},p[n++]= {w,h},p[n++]= {w,0},p[n++]= {0,h};
            sort(p,p+n,[](Node x,Node y)
            {
                return x.x<y.x;
            });
            int ans_x=1,ans_y=1,ans_l=1;
            for(int i=0; i<n; i++)
            {
                int up=h,down=0;
                for(int j=i+1; j<n; j++)
                {
                    if(p[j].x==p[i].x)
                        continue;
                    int ly=up-down;
                    int lx=p[j].x-p[i].x;
                    int ans=min(lx,ly);
                    if(ans>ans_l)
                    {
                        ans_l=ans;
                        ans_x=p[i].x;
                        ans_y=down;
                    }
                    if(p[i].y==p[j].y)
                        break;
                    if(p[j].y>p[i].y)
                        up=min(up,p[j].y);
                    if(p[j].y<p[i].y)
                        down=max(down,p[j].y);
                }
            }
            for(int i=n-1; i>=0; i--)
            {
                int up=h,down=0;
                for(int j=i+1; j<n; j++)
                {
                    if(p[j].x==p[i].x)
                        continue;
                    int ly=up-down;
                    int lx=p[j].x-p[i].x;
                    int ans=min(lx,ly);
                    if(ans>ans_l)
                    {
                        ans_l=ans;
                        ans_x=p[i].x;
                        ans_y=down;
                    }
                    if(p[i].y==p[j].y)
                        break;
                    if(p[j].y>p[i].y)
                        up=min(up,p[j].y);
                    if(p[j].y<p[i].y)
                        down=max(down,p[j].y);
                }
            }
            sort(p,p+n,[](Node x,Node y)
            {
                return x.y<y.y;
            });
            for(int i=0; i<n; i++)
            {
                int j=i;
                while(j<n&&p[j].y==p[i].y)
                    j++;
                if(j==n)
                    break;
                int len=min(p[j].y-p[i].y,w);
                if(len>ans_l)
                {
                    ans_l=len;
                    ans_x=0;
                    ans_y=p[i].y;
                }
            }
            cout<<ans_x<<' '<<ans_y<<' '<<ans_l<<endl;
            if(T)
                cout<<endl;
        }
    }
    
    
    
    /*
    void read()
    {
    
        char c = getchar();
        int x = 0;
        for (; (c < 48 || c>57); c = getchar());
        for (; c > 47 && c < 58; c = getchar())
        {
            x = (x << 1) + (x << 3) + c - 48;
        }
        return x;
    }
    */
  • 相关阅读:
    Android 获取SDCard中某个目录下图片
    Android ListView中 每一项都有不同的布局
    Listview 异步加载图片之优化篇(有图有码有解释)
    Android 实现ListView异步加载图片
    android ListView异步加载图片(双缓存)
    使用 COM 风格的编程接口
    deb包+软件图标+添加到系统菜单+举例安装卸载
    罗将公布手机锤,我感到深深的内疚
    【 D3.js 入门系列 --- 9.6 】 生产的包图
    Junit指定测试运行顺序
  • 原文地址:https://www.cnblogs.com/033000-/p/10640020.html
Copyright © 2011-2022 走看看