【Codeforces Round 276 (Div 2)B】【水题】Valuable Resources 最小正方形包含所有点

B. Valuable Resources
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.

Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.

Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.

Input

The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct.

Output

Print the minimum area of the city that can cover all the mines with valuable resources.

Sample test(s)
input
2
0 0
2 2
output
4
input
2
0 0
0 3
output
9
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		LL minx=1e9;
		LL miny=1e9;
		LL maxx=-1e9;
		LL maxy=-1e9;
		for(int i=1;i<=n;++i)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			gmin(minx,x);
			gmin(miny,y);
			gmax(maxx,x);
			gmax(maxy,y);
		}
		LL len=max(maxx-minx,maxy-miny);
		printf("%lld\n",len*len);
	}
	return 0;
}
/*
【trick&&吐槽】
这种题要堤防面积不能为0哦。
虽然这道题的面积可以是为0的。

【题意】
给你n(2<=n<=1000)个点,每个点的坐标都在[-1e9,1e9]之间。
问你一个最小面积的正方形的面积,使得该正方形包含所有点。

【类型】
水题

【分析】
直接更新坐标的最小值和最大值,然后调整成最小正方形求面积即可。

*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值