cf A. Wilbur and Swimming Pool

来源:互联网 发布:剑灵女枪手捏脸数据图 编辑:程序博客网 时间:2024/06/04 19:21


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 test(s)
input
20 01 1
output
1
input
11 1
output
-1


#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<queue>#include<stack>#include<cmath>using namespace std;typedef long long ll;int x[5],y[5];int main(){int n,i,j;int ans;cin>>n;for(i=1;i<=n;i++) cin>>x[i]>>y[i];if(n==1) cout<<"-1"<<endl;else if(n==2) {if(x[1]==x[2]||y[1]==y[2]) cout<<"-1"<<endl;else {ans=(x[1]-x[2])*(y[1]-y[2]);if(ans<0) ans=-ans;cout<<ans<<endl;}}else {sort(x+1,x+1+n);     sort(y+1,y+1+n);     ans=(x[1]-x[3])*(y[1]-y[3]);     if(ans<0) ans=-ans;     cout<<ans<<endl;}return 0;} 



0 0
原创粉丝点击