Codeforces--596A--Wilbur and Swimming Pool(数学)

来源:互联网 发布:php租车系统源码 编辑:程序博客网 时间:2024/06/05 05:26

A - Wilbur and Swimming Pool

Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

SubmitStatus 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 werenot erased by Wilbur's friend.

Each of the following n lines contains two integersxi andyi ( - 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

Sample Output

Hint

In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.

In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.

给了n个点,判断这n个点能否确定一个矩形,可以的话,输出最大面积,否则输出-1,如果点都在一条直线上那么肯定是不能组成长方形的,每次记录最大最小的横纵坐标就行

#include<cstdio>#include<iostream>#include<algorithm>using namespace std;struct node{int x,y;}p[10];int main(){int n;while(cin>>n){int x,y,tempx,tempy;int minx=0x3f3f3f,miny=0x3f3f3f;int maxx=-0x3f3f3f,maxy=-0x3f3f3f;for(int i=1;i<=n;i++){cin>>p[i].x>>p[i].y;minx=min(minx,p[i].x);maxx=max(maxx,p[i].x);miny=min(miny,p[i].y);maxy=max(maxy,p[i].y);}if(n==1)cout<<-1<<endl;else{int ans=(maxx-minx)*(maxy-miny);if(maxx==minx||maxy==miny)cout<<-1<<endl;elsecout<<ans<<endl;}}return 0;}

0 0
原创粉丝点击