Bzoj 1052: [HAOI2007] cover problem two points, greedy __acm/icpc_

Source: Internet
Author: User

Description
Someone planted n small saplings on the mountain. Winter came, the temperature dropped rapidly, small seedlings vulnerable to fragile, so the tree owners want to use some plastic thin
The film covered the small trees, and after a long thought, he decided to cover them with 3 l*l square plastic sheeting. We may as well build the mountain
A planar rectangular coordinate system is set, the coordinates of the tree I tree are (xi,yi), and the sides of the 3 l*l squares are required to be parallel with the axes, a point if in
On the boundary of the square, also counted as being covered. Of course, we hope that the smaller the film area, the better, that is, the L-min value.
Input
The first row has a positive integer n, indicating how many trees there are. Then there are n rows, and the i+1 line has 2 integers xi,yi, representing the coordinates of the tree, which guarantees
There will not be 2 trees with the same coordinates.
Output

One line, the smallest l value is output.
Sample Input
4

0 1

0-1

1 0

-1 0
Sample Output
1
HINT

100% of the data, n<=20000.

How to solve the problem: circle all the points with a minimum rectangle, and obviously the first square is placed in one of the Four Corners,
By deleting the points it covers, the remaining points become a child problem, and then a square is placed to determine whether the remaining points are in a square. Then this side will be two minutes long.

The code is as follows:

#include <bits/stdc++.h> using namespace std;
const int MAXN = 20010;
const int inf = 1<<30;
int n;
BOOL VIS[MAXN];
    struct point{int x, y;
    Point () {} point (int x, int y): x (x), Y (y) {} void Read () {scanf ("%d%d", &x, &y);
}}P[MAXN]; BOOL Check (int l, int step) {if (step = 4) {to (int i = 1; I <= n; i++) {if (!vis[i)) return FAL
        Se
    return true;
    int xl = inf, XR =-inf, yl = inf, yr =-inf;
    int X, Y;
    BOOL flag = 0;
            for (int i = 1; I <= n; i++) {if (!vis[i]) {xl = min (p[i].x, xl); XR = max (XR, p[i].x); yl = min (p[i].y, yl);
        yr = Max (yr, p[i].y);
        for (int i = 1; I <= 4; i++) {if (i = = 1) X = XL, Y = YL;
        else if (i = = 2) X = XR, Y = YL;
        else if (i = = 3) X = xl, Y = yr;
        else X = XR, Y = yr;
        Vector <int> xs; for (int j = 1; J <= N; j +) {if (!vis[j] && X-L <= p[j].x && p[j].x <= x + L && y-l <= p[j].y && p[j].y <= Y + L) {
                VIS[J] = 1;
            Xs.push_back (j);
        } Flag |= Check (l, step + 1);
        for (int j = 0; J < Xs.size (); j + +) {Vis[xs[j]] = 0;
} return flag;
    int main () {scanf ("%d", &n);
    for (int i = 1; I <= n; i++) P[i].read ();
    int L = 0, r = INF;
        while (L < r) {int mid = (L + r)/2;
        if (check (Mid, 1)) R = Mid;
    else L = mid + 1;
    printf ("%d\n", L);
return 0;
 }

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.