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. Delphi7 安装ICS,与简单使用

    官网 http://www.overbyte.be/ 下载 OverbyteIcsV816 完成后解压到E:\Delphi7\OverbyteIcsV816\ 1.在library里加入E:\Delp ...

  2. rsyslog 日志统一搜集&message格式

        日志格式修改: http://jiechao2012.blog.51cto.com/3251753/1143762 http://yulei7633.blog.51cto.com/149275 ...

  3. c语言 指针的值

    int num = 1; int *p = &num; printf("%x", &num);//打印 0x7dfe88 printf("\n%x&quo ...

  4. CAS 单点登录流程

    经验:在网上学东西不要指望一篇文章就能让你明白——我在网上学CAS流程,看了五六篇博文,其中三篇是觉得作者表达能力不行,或者作者自己就没明白怎么回事就出来写东西,看到一半就跳过了,剩下两篇每篇看了两遍 ...

  5. Java 8新特性——default方法(defender方法)介绍

    我们都知道在Java语言的接口中只能定义方法名,而不能包含方法的具体实现代码.接口中定义的方法必须在接口的非抽象子类中实现.下面就是关于接口的一个例子: 1 2 3 4 5 6 7 8 9 10 11 ...

  6. Android启停调试

    环境配置 java jdk android sdk eclipse + adt 参考资料: http://tools.android-studio.org/#userconsent# android ...

  7. C#报错:创建调试信息文件 ……obj\Debug\model.pdb: 拒绝访问

    错误:创建调试信息文件“.......\obj\Debug\model.pdb”时发生错误 --“......\obj\Debug\model.pdb: 拒绝访问. 解决办法如下: 删除该项目下的 b ...

  8. 一款Android开源的下拉刷新动画

    无意间在GitHub看到的,就Down了下来.但是作者是用AndroidStudio开发的,这边移动Eclipse供小伙伴们下载使用. 截图 这么好的东西因为字数不够不让分享,得了,贴段代码吧 pac ...

  9. Nginx学习记录

    本人刚刚接触Nginx,对这个强大的服务器还没有充分的了解,现在在这里对我在使用Nginx的过程中碰到的一些问题做些总结! 1.ssi配置问题 这里我贴上我的nginx.conf配置文件中server ...

  10. SpringMVC实现上传和下载

    摘要 有些下载的错误解决来 java.lang.IllegalStateException: getOutputStream() has already been called for this re ...