宝贵资源
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
有一个城市需要建造,给你 N 个矿场的坐标 X , Y ,问把这么多矿坑全都包进城市的话,城市所需最小面积是多少(注意,城市为平行于坐标轴的正方形)
Input
第一行为 N ,表示矿场数目
下面为 N 行 每行两个数字 xi , yi ,表示第 i 行表示第 i 个矿场的坐标
2≤N≤1000
0≤xi,yi≤1000000000
Output
城市所需最小面积
Sample input and output
Sample Input | Sample Output |
---|---|
2 0 0 2 2 | 4 |
Hint
long long 请使用%lld输入输出
//虽是个水题,但却被坑了两次(是自己不细心没看到是正方形)。。。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int x[1010];
int y[1010];
int main()
{
int n;
ll sum,x1,y1,mm;
int i,j;
while(scanf("%d",&n)!=EOF)
{
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
for(i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
sort(x,x+n);sort(y,y+n);
x1=(ll)(x[n-1]-x[0]);
y1=(ll)(y[n-1]-y[0]);
mm=max(x1,y1);
sum=mm*mm;
printf("%lld\n",sum);
}
return 0;
}