您的位置:首页 > 其它

CodeForces 596A

2016-03-19 13:35 357 查看
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

Input
2
0 0
1 1


Output
1


Input
11 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: