Codeforces Round #331 (Div. 2)-Wilbur and Swimming Pool(模拟)

来源:互联网 发布:陆克文女儿的淘宝店 编辑:程序博客网 时间:2024/06/16 03:20
A. Wilbur and Swimming Pool
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
Note

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.


这题注意一下2个点的情况是x,y都不能存在相等的就行了。。

AC代码:

#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<vector>#include<cstdio>#include<cmath>using namespace std;#define CRL(a) memset(a,0,sizeof(a))typedef unsigned __int64 ll;#define T 10005#define mod 1000000007int main(){#ifdef zsc    freopen("input.txt","r",stdin);#endif    int n,m,k,i,j;    int x[4],y[4];    while(~scanf("%d",&n))    {        for(i=0;i<n;++i){            scanf("%d%d",&x[i],&y[i]);        }        if(n==1){            printf("-1\n");        }        else if(n==3||n==4){            int tmpx,tmpy;            for(i=0;i<n;++i){                for(j=0;j<n;++j){                    if(j==i)continue;                    if(x[i]==x[j]){                        tmpy = y[i]-y[j];                        if(tmpy<0)tmpy=-tmpy;                    }                    if(y[i]==y[j]){                        tmpx = x[i]-x[j];                        if(tmpx<0)tmpx=-tmpx;                    }                }            }            printf("%d\n",tmpy*tmpx);        }        else        {            if(x[0]==x[1]||y[0]==y[1]){                printf("-1\n");continue;            }            int tmpx = x[0]-x[1],tmpy=y[0]-y[1];            if(tmpx<0)tmpx=-tmpx;            if(tmpy<0)tmpy=-tmpy;            printf("%d\n",tmpy*tmpx);        }    }    return 0;}


0 0
原创粉丝点击