UESTC--1265--宝贵资源(简单数学)

Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu

Status

Description

有一个城市需要建造,给你$N$个矿场的坐标$X$,$Y$,问把这么多矿坑全都包进城市的话,城市所需最小面积是多少(注意,城市为平行于坐标轴的正方形)

Input

第一行为$N$,表示矿场数目

下面为$N$行 每行两个数字$x_i$,$y_i$,表示第$i$行表示第$i$个矿场的坐标

$2≤N≤1000$

$0≤x_i,y_i≤1000 000 000$

Output

城市所需最小面积

Sample Input

2
0 0
2 2

Sample Output

4

Hint

long long 请使用%lld输入输出

Source

第七届ACM趣味程序设计竞赛第三场(正式赛)

正方形!!!!!一定要注意啊,这还真是趣味程序竞赛

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 1010
#define MAXM 10010
#define INF 0xfffffff
struct node
{
	long long x,y;
}p[MAXN];
//int cmp(node s1,node s2)
//{
//	if(s1.x<s2.x)
//	return 1;
//	if(s1.x==s2.x)
//	return s1.y<s2.y;
//	return 0;
//}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int x,y,a,b;
		long long x1,x2,y1,y2;
		x1=y1=INF;
		x2=y2=-INF;
		for(int i=0;i<n;i++)
		{
			scanf("%lld%lld",&p[i].x,&p[i].y);
			x1=min(x1,p[i].x);y1=min(y1,p[i].y);
			x2=max(x2,p[i].x);y2=max(y2,p[i].y);
		}
//		sort(p,p+n,cmp);
		long long s=0;
//		s=max((p[n-1].x-p[0].x)*(p[n-1].x-p[0].x),(p[n-1].y-p[0].y)*(p[n-1].y-p[0].y));
		s=max((x2-x1)*(x2-x1),(y2-y1)*(y2-y1));
		printf("%lld
",s);
	}
	return 0;
}


原文地址:https://www.cnblogs.com/playboy307/p/5273509.html