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

题意:输入若干个点判断能否确定一个矩形的面积,矩形平行于坐标轴

开始正常写,提交WA,然后改,始终没能找到错误。最后才发现自己思维太不严谨了

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int flag,n;
struct node
{
int x,y;
};
node a[];
int main()
{
while(scanf("%d", &n) != EOF)
{
flag = ;
int s;
for(int i = ; i < n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
if(n < )
flag = ;
else
{
if(n == )
{
if(a[].x == a[].x || a[].y == a[].y)
{
flag = ;
}
else
{
s = abs(a[].x - a[].x) * abs(a[].y - a[].y);
}
}
else
{
if ((a[].x == a[].x || a[].y == a[].y) && (a[].x == a[].x || a[].y == a[].y) ) //就是落了这个判断条件。。。。。。
s = abs(a[].x - a[].x) * abs(a[].y - a[].y);
else
for(int i = ; i < n; i++)
{
if(a[].x == a[i].x || a[].y == a[i].y)
continue;
else
s = abs(a[].x - a[i].x) * abs(a[].y - a[i].y);
}
}
}
if(flag)
printf("-1\n");
else
printf("%d\n",s);
}
return ;
}

Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)的更多相关文章

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

    A. Wilbur and Swimming Pool Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  2. 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 megabytes input s ...

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

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

  4. Codeforces Round #331 (Div. 2) E. Wilbur and Strings dfs乱搞

    E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...

  5. Codeforces Round #331 (Div. 2) D. Wilbur and Trees 记忆化搜索

    D. Wilbur and Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

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

    C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...

  7. Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题

    B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  8. Codeforces Round #331 (Div. 2) B. Wilbur and Array

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

  9. CodeForces 596A Wilbur and Swimming Pool

    水题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...

随机推荐

  1. mysql客户端授权后连接失败问题

    在本地(192.168.1.152)部署好mysql环境,授权远程客户机192.168.1.%连接本机的mysql,在iptables防火墙也已开通3306端口.如下:mysql> select ...

  2. javascript:让表单 文本框 只读,不可编辑的方法

    有时候,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使<input type="text" name="input1" value=&qu ...

  3. 一些正则验证-JS

    Validation = { textCount: function(field, counter, maxLimit) { var message = $(field).val(); if ($(f ...

  4. 如何设置word里的代码格式,使之有底纹的效果

    1.测试平台:word2013 2.步骤:设计->底纹->填充->应用于->确定 3.效果:

  5. 通过spring,在项目的任意位置获取当前Request

    需要引入: import javax.servlet.http.HttpServletRequest; import org.springframework.web.context.request.R ...

  6. jQuery Event.stopPropagation() 函数详解

    stopPropagation()函数用于阻止当前事件在DOM树上冒泡. 根据DOM事件流机制,在元素上触发的大多数事件都会冒泡传递到该元素的所有祖辈元素上,如果这些祖辈元素上也绑定了相应的事件处理函 ...

  7. windows下怎么打开psql命令

    你是直接执行的psql.exe吧? 那么需要加入数据库位置等一些参数的.Windows系统下,PostgreSQL有提供一个命令行脚本runsql.bat, 在安装目录的scripts文件夹中,一般是 ...

  8. poj1082-Calendar Game-博弈/sg

    sg大法好 无脑sg即可,不用去找规律了. /*---------------------------------------------------------------------------- ...

  9. C#基础之yield与Singleton

    1.实例解析yiled的作用 最近参加java笔试题第一次见到yield这个关键字,既然遇见了那肯定要掌握,下面是C#中关于yield关键字的总结.yield这个关键字作用于迭代器块中,其最本质的功能 ...

  10. html的转码玉反转码

    function HTMLEncode(html) { var temp = document.createElement ("div"); (temp.textContent ! ...