B - Valuable Resources
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.
Examples
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9
题意是在输入的坐标中找出最长的x或y的坐标差的绝对值,但是要注意在加减的过程中会超出int范围,使用long long解决问题
#include"iostream"
#include"algorithm"
using namespace std;
int main()
{
long long i,n,max1,x[1005],y[1005];
i=0;
cin>>n;
while(i!=n)
{
cin>>x[i]>>y[i];
i++;
}
sort(x,x+n);
sort(y,y+n);
max1=max(x[n-1]-x[0],y[n-1]-y[0]);
cout<<max1*max1<<endl;
return 0;
}
本文介绍了一种算法,用于解决计算机策略游戏中构建城市的问题。目标是最小化城市的面积,同时确保所有有价值的资源矿点位于城市内或边界上。通过读取输入坐标,算法计算并输出覆盖所有资源的最小城市面积。
292

被折叠的 条评论
为什么被折叠?



