Codeforces Round #331 (Div. 2) 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
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
#include
#include
#include
using namespace std;

struct node
{
int x;
int y;
}a[10];

int abs(int x)
{
if(x > 0) return x;
return -x;
}

int main(void)
{
int i, j;
int n;
scanf("%d", &n);
int ans = -1;
for(i = 0; i < n; i++)
{
scanf("%d%d", &a[i].x, &a[i].y);
}
for(i = 0; i < n; i++)
{
for(j = i+1; j < n; j++)
{
if(a[i].x != a[j].x && a[i].y != a[j].y)
{
ans = abs(a[i].x - a[j].x)*abs(a[i].y - a[j].y);
}
}
}
printf("%d\n", ans);
return 0;
}

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

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

• zyx520ytt
• 2015年11月16日 10:25
• 174

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
• 303

Codeforces Round #331 (Div. 2)A. Wilbur and Swimming Pool（简单计算）

• u013167299
• 2015年11月16日 11:08
• 213

Codeforces Round #327 (div.2)(A B C D)

codeforces round #327 (div.2)
• lincifer
• 2015年10月26日 13:11
• 1101

Codeforces Round #444 (Div. 2)-贪心&尺取-Ratings and Reality Shows

http://codeforces.com/contest/887/problem/D 一个模特有两种活动。 ① 拍照片，挣钱 a。 ②开演唱会，花费b 给定模特这两种工作的时间表。 模特可以...
• qq_35781950
• 2017年11月11日 20:11
• 130

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

A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megab...
• zsc2014030403015
• 2015年11月16日 09:16
• 285

Codeforces Round #431 (Div. 2) A. Odds and Ends 题解

• LamdaSniper
• 2017年09月03日 16:13
• 234

Codeforces Round #258 (Div. 2)-(A,B,C,D,E)

A:Game With Sticks 水题。。。每次操作，都会拿走一个横行，一个竖行。 所以一共会操作min（横行，竖行）次。 #include #include #include #include ...
• rowanhaoa
• 2014年07月25日 14:39
• 1485

【解题报告】Codeforces Round #401 (Div. 2)

• TRiddle
• 2017年02月25日 17:55
• 416

【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
• 445

举报原因： 您举报文章：Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)