# 【Codeforces Round 331 (Div 2)A】【水题】Wilbur and Swimming Pool 给出矩形1~4个顶点让你还原矩形

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
2
0 0
1 1

output
1

input
1
1 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.

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int x[4];
int y[4];
int n;
int main()
{
while(~scanf("%d",&n))
{
int maxx=-1e9;
int minx=1e9;
int maxy=-1e9;
int miny=1e9;
for(int i=1;i<=n;++i)
{
scanf("%d%d",&x[i],&y[i]);
gmax(maxx,x[i]);
gmax(maxy,y[i]);
gmin(minx,x[i]);
gmin(miny,y[i]);
}
int ans=(maxx-minx)*(maxy-miny);
if(ans==0)ans=-1;
printf("%d\n",ans);
}
return 0;
}
/*
【trick&&吐槽】

【题意】

【类型】

【分析】

*/

• 本文已收录于以下专栏：

## CodeForces 596 A Wilbur and Swimming Pool【数学】

A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes i...
• liuke19950717
• 2016年03月12日 15:39
• 185

## Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool

A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megab...
• xiaotan1314
• 2015年11月16日 13:20
• 302

## CodeForces 596A：Wilbur and Swimming Pool【水】

Wilbur and Swimming Pool Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I...
• lin14543
• 2016年03月12日 16:44
• 260

## Codeforces 596A Wilbur and Swimming Pool 【水题】

A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes i...
• chenzhenyu123456
• 2015年11月17日 17:15
• 779

## LintCode全AC题解（共331题）

LintCode全AC解（共331题）
• gg_18826075157
• 2017年09月08日 12:00
• 258

## 【Codeforces Round 331 (Div 2)A】【水题】Wilbur and Swimming Pool 给出矩形1~4个顶点让你还原矩形

Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabyte...
• snowy_smile
• 2015年12月03日 21:53
• 444

## nyoj 206 矩形的个数 【规律题】

• dxx_111
• 2015年08月31日 13:25
• 1518

## Codeforces Round #172 (Div. 1) BMaximum Xor Secondary 单调栈

//给一个长度为N的个不相同的序列，找出所有区间中最大值和第二大数的异或值最大的值 //对于所有区间只需要找其最大值和第二大数，所以对于很多区间的结果是重复的 //对于每一个数，它起作用的区间只有...
• cq_pf
• 2015年05月26日 19:12
• 708

## 矩形的个数06

• quentain
• 2015年11月25日 20:04
• 285

## NYOJ矩形的个数

• zhu1534120216
• 2016年07月16日 08:12
• 156

举报原因： 您举报文章：【Codeforces Round 331 (Div 2)A】【水题】Wilbur and Swimming Pool 给出矩形1~4个顶点让你还原矩形 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)