Algorithm title: UVA 1312

Source: Internet
Author: User

The main effect of the topic:

Give n points on the coordinates of the w*h and then ask for a maximum rectangle so that there is no point within the rectangle (excluding the boundary), notice that the boundary can be somewhat.

First of all, the discretization of these coordinates, discrete words to pay attention to, if there are two points of the original coordinates are not adjacent, but after the discretization has become adjacent, at this time to add a point between them.

After preprocessing, enumerate the upper and lower bounds of the rectangle and then use the complexity of O (n) to find the left and right edges.

Code:

#include <iostream> #include <cstdio> #include <algorithm> #include <cctype> #include <cstr  
    
Ing> using namespace std;  
const int MAXN = 120;  
int n,w,h;  
int row, col;  
int D[MAXN];  
int arr[maxn][2];  
int X[MAXN], Y[MAXN];  
int idx[10010], idy[10010];  
    
    
int MAT[MAXN][MAXN];  
    inline void input () {x[0] = y[0] = 0;  
    
    row = col = 1;  
        Input and discretization for (int i=0; i<n; ++i) {scanf ("%d%d", &arr[i][0], &arr[i][1]);  
        x[row++] = arr[i][0];  
    y[col++] = arr[i][1];  
    } x[row++] = W;  
    y[col++] = h;  
    Sort (x, X+row);  
    Sort (y, y+col);  
    row = unique (x, X+row)-X;  
        
    Col = unique (y, y+col)-y;  
    int end = row;  
    for (int i=1; i<end; ++i) if (X[i]!= x[i-1]+1) {x[row++] = x[i-1] + 1;   
    } end = col;  
    for (int i=1; i<end; ++i) if (Y[i]!= y[i-1]+1) {y[col++] = y[i-1] + 1; Sort (x, X+row); 
    Sort (y, y+col);  
    for (int i=0; i<row; ++i) idx[x[i] = i;  
    
    for (int i=0; i<col; ++i) idy[y[i] = i;  
    Memset (Mat, 0, sizeof (MAT));  
        for (int i=0; i<n; ++i) {int a = idx[arr[i][0]];  
        int b = idy[arr[i][1]];  
    MAT[A][B] = 1; for (int i=0; i<row; ++i) {for (int j=0; j<col; ++j) {if (i==0) mat[i][j] = = Mat[i][j-1  
            ];  
            else if (j==0) mat[i][j] + = mat[i-1][j];  
        else Mat[i][j] + = Mat[i][j-1] + mat[i-1][j]-mat[i-1][j-1];  
    }} inline void Solve () {int maxlen=1, max_x=0, max_y=0;  
        
    int xx, yy; for (int low=0; low<row-1; ++low) {for (int up=low+1; up<row; ++up) {memset (d, 0, siz  
        EOF (d));  
            for (int j=0; j<col; ++j) {int tmp; if (j>0) {tmp = Mat[up][j]-mat[low][j]-(mat[up][j-1]-mat[low][j-1]);  
            }else{tmp = Mat[up][j]-mat[low][j];  
                } if (tmp = = 0) {D[j] = d[j-1] + 1;  
                int low_x = max (low, 0);  
                int low_y = max (J-d[j], 0);  
                int up_x = min (row-1, up+1);  
    
                int up_y = min (col-1, j+1);  
                int hh = x[up_x]-x[low_x];  
                int ww = y[up_y]-y[low_y];  
    
                int ll = min (hh, WW);  
                    if (ll > maxlen) {maxlen = ll;  
                    max_x = low_x;  
                    max_y = low_y;  
                    xx = up_x;  
                yy = up_y;  
("%d%d%d\n", x[max_x], y[max_y], maxlen);  
    int main () {int ncase;  
    BOOL First=true;  
        
    scanf ("%d", &ncase); while (ncase--) {scanf ("%d%d%d"), &AMp;n, &w, &h); A.  
        First=false:putchar (' \ n ');  
            if (n==0) {printf ("%d%d%d\n", 0,0,min (w,h));  
        Continue  
        Input ();  
    Solve ();  
return 0; }

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.