Codeforces 485B Valuable Resources(水题)

题目链接:Codeforces485B Valuable Resources

题目大意:给定一些点,要用尽量小的正方形框住所有的点,输出矩形的大小。

解题思路:维护x的最大值和最小值。同理y。然后取差值中的最大值作为变成,注意用long long

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int inf = 0x3f3f3f3f;

int main () {
    int N, x, y;
    int Tx = -inf, Ty = -inf, Bx = inf, By = inf;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d%d", &x, &y);
        Tx = max(Tx, x);
        Ty = max(Ty, y);
        Bx = min(Bx, x);
        By = min(By, y);
    }
    long long r = max(Tx - Bx, Ty - By);
    printf("%lld\n", r * r);
    return 0;
}

你可能感兴趣的:(Codeforces 485B Valuable Resources(水题))