Points on a Rectangle

Sort by

recency

|

7 Discussions

|

  • + 0 comments

    def solve(coordinates):

    d = dict(coordinates)
    
    y = d.values()
    x = d.keys()
    
    min_x = min(x)
    max_x = max(x)
    min_y = min(y)
    max_y = max(y)
    
    ret = "YES"
    for el in coordinates:
        if (el[0] > min_x) & (el[0] < max_x) & (el[1] > min_y) & (el[1] < max_y):
            ret = "NO"
            break
    return ret
    
  • + 1 comment
    #include <stdio.h>
    int main ()
    {
        int i, q;
        scanf("%d", &q);
        for (i = 1; i <= q; i++)
        {
            int j, n, minx, maxx, miny, maxy, count = 0;
            scanf("%d", &n);
            int x[n], y[n];
            for (j = 0; j < n; j++)
            {
                scanf("%d %d", &x[j], &y[j]);
            }
            minx = x[0], maxx = x[0], miny = y[0], maxy = y[0];
            for (j = 1; j < n; j++)
            {
                if (x[j] < minx)
                {
                    minx = x[j];
                }
                if (x[j] > maxx)
                {
                    maxx = x[j];
                }
                if (y[j] < miny)
                {
                    miny = y[j];
                }
                if (y[j] > maxy)
                {
                    maxy = y[j];
                }
            }
            for (j = 0; j < n; j++)
            {
                if (x[j] > minx && x[j] < maxx && y[j] > miny && y[j] < maxy)
                {
                    count++;
                }
            }
            if (count > 0)
            {
                printf("NO\n");
            }
            else
            {
                printf("YES\n");
            }
        }
    }
    
  • + 0 comments

    Another approach: if the x coordinate is in [max_x, min_x] or the y_coordinate is in [max_y, min_y] for every point in the set, then it is a rectangle parallel to the axes because otherwise there would either be a point outside or inside the rectangle

  • + 0 comments

    include

    include

    include

    include

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int t; scanf("%d",&t); while(t--) { int n,x[10],y[10],i,minx=10000,maxx=-10000,miny=10000,maxy=-10000; int flag=0; scanf("%d",&n); for(i=0;i=x[i]) minx=x[i]; if(maxx<=x[i]) maxx=x[i]; if(miny>=y[i]) miny=y[i]; if(maxy<=y[i]) maxy=y[i]; } //printf("%d\t%d\t%d\t%d\n",minx,maxx,miny,maxy); for(i=0;i

        }
        if(flag==1)
            printf("NO");
        else
            printf("YES");
        printf("\n");
    }
    return 0;
    

    }

  • + 0 comments

    note that the question only asks for axis parallel rectangles, e.g. sides are either vertical or horizontal lines. Without this restriction, the problem would be significantly more nontrivial!