CodeForces 596A--Wilbur and Swimming Pool

来源:互联网 发布:印度软件 编辑:程序博客网 时间:2024/06/05 03:15
A - Wilbur and Swimming Pool
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 596A

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
20 01 1
Output
1
Input
11 1
Output
-1

题目:给你一个矩形的几个顶点,判断是否能构成矩形,如果可以的话,矩形的面积是多少,不可以的话,输出-1;

ac代码:

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;int main(){int n;int x[5],y[5];bool flag;while(scanf("%d",&n)!=EOF){flag=true;for(int i=1;i<=n;i++){scanf("%d%d",&x[i],&y[i]);}if(n==1){printf("-1\n");continue ;}sort(x+1,x+n+1);sort(y+1,y+n+1);int xa=x[1],xb=x[n];int ya=y[1],yb=y[n];if((xa==xb)||(ya==yb))flag=false;for(int i=1;i<=n;i++){if(x[i]!=xa&&x[i]!=xb){flag=false;break;}if(y[i]!=ya&&y[i]!=yb){flag=false;break;}}int s=(xb-xa)*(yb-ya);if(flag)printf("%d\n",s);elseprintf("-1\n");}return 0;}


0 0
原创粉丝点击