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

题意:给你n个点,求矩形面积。要求矩形的每条边与坐标轴平行。如果不能得出,则输出-1; #include #include #include #include using namespace std...
  • zyx520ytt
  • 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
  • xiaotan1314
  • 2015年11月16日 13:20
  • 303

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

题目链接 题意:给出n个点,问能否计算出以这n(n
  • u013167299
  • u013167299
  • 2015年11月16日 11:08
  • 213

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

codeforces round #327 (div.2)
  • lincifer
  • 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
  • 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
  • zsc2014030403015
  • 2015年11月16日 09:16
  • 285

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

题目: A. Odds and Ends time limit per test 1 second memory limit per test 256 megabyt...
  • LamdaSniper
  • 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
  • rowanhaoa
  • 2014年07月25日 14:39
  • 1485

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

简略的解题报告。
  • TRiddle
  • 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
  • snowy_smile
  • 2015年12月03日 21:53
  • 445
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
举报原因:
原因补充:

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