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

原创 2015年11月17日 16:02:53
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.


题意:有一个矩形,矩形的边和坐标轴平行,已知n个点求矩形的面积,如果求不出输出-1
题目简单,要仔细看懂题目的意思,才开始做。
直接判断是否存在对角线上的两点,如果存在面积才可以算出,否者不能算。
#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 给出矩形1~4个顶点让你还原矩形

Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabyte...

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

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

Codeforces Round #331 (Div. 2) C. Wilbur and Points

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandar...

Codeforces Round #331 (Div. 2)——C. Wilbur and Points

MD,又因为一个傻逼错误搞了一个下午+一个晚上。。忧桑= = 题意: 现在有n个点,然后给出n个点的x,y坐标。然后这些坐标必须满足条件:比如说分配给点(x,y)的标号是i,那么点(x',y')的标号...

【Codeforces Round 331 (Div 2)C】【脑洞 SET贪心写法】Wilbur and Points 锯齿图形差值编号,右上角的最大

Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input stan...

【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b

Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces Round #331 (Div. 2) C. Wilbur and Points 贪心+排序

题目~~ 题意: 有n个坐标,wi为(yi-xi),再给出n个wj(j=0~n), wi==wj 则第i个坐标标号为j,而满足xi...

CodeForces 596A-Wilbur and Swimming Pool

After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a ...

Codeforces Round #331 D. Wilbur and Trees(概率dp+区间dp)

题意:在一条直线上有n棵树,每棵树的高度都为h,每次等概率的砍掉最左边或最右边的树,一棵树如果被砍掉有p的概率向左倒下,有1-p的概率向右倒下,如果两树之间距离小于h,那么一颗树倒下后可以击中另一棵树...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
举报原因:
原因补充:

(最多只允许输入30个字)