您的位置:首页 > 编程语言 > Lua

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

2015-12-08 16:31 525 查看
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]之间。
问你一个最小面积的正方形的面积,使得该正方形包含所有点。

【类型】
水题

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

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息