CodeForces 596A

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mml5211314/article/details/50930670

A - Wilbur and Swimming Pool
微笑

Description

After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.

Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend.

Each of the following n lines contains two integers xi and yi ( - 1000 ≤ xi, yi ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.

It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.

Output

Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print  - 1.

Sample Input

扫描二维码关注公众号,回复: 4123653 查看本文章
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1

//解题思路:给出n个点的坐标,计算包含这几个点的最小水池的面积,sort()排序出x轴的最长距离,y轴的最长距离,然后求出矩形面积就行

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int x[1010],y[1010];
	while (scanf ("%d",&n)!=EOF)
	{
		for (int i=0;i<n;i++)
		scanf ("%d%d",&x[i],&y[i]);
		sort(x,x+n);
		sort(y,y+n);
		int dx=x[n-1]-x[0];
		int dy=y[n-1]-y[0];
		long long sum=dx*dy;
		if (sum)
		printf ("%lld\n",sum);
		else
		printf ("-1\n");
	}
	return 0;
}









猜你喜欢

转载自blog.csdn.net/mml5211314/article/details/50930670
今日推荐