【CodeForces 596A】E - 特别水的题5-Wilbur and Swimming Pool

时间:2022-09-18 19:51:55

Description

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 Input

Input

2
0 0
1 1

Output

1

Input

1
1 1

Output

-1

Hint

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、2、3、4的情况,n=3或者4时用循环找出x,y坐标不同的两点,面积要绝对值。

或者不要讨论,直接在读入的时候,找出x,y的最大值和最小值,计算面积如果面积==0,,那就输出-1,代码如下:

#include<stdio.h>
#include<algorithm>
using namespace std;
long long n,area,xmin=,ymin=,xmax=-,ymax=-;
struct Node
{
long long x,y;
} node[];
int main()
{
scanf("%lld",&n);
for(int i=; i<n; i++)
{
scanf("%lld%lld",&node[i].x,&node[i].y);
xmax=max(xmax,node[i].x);
xmin=min(xmin,node[i].x);
ymax=max(ymax,node[i].y);
ymin=min(ymin,node[i].y);
}
area=(ymax-ymin)*(xmax-xmin);
if(area)printf("%lld\n",area);
else printf("-1\n");
return ;
}

  

【CodeForces 596A】E - 特别水的题5-Wilbur and Swimming Pool的更多相关文章

  1. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; A&period; Wilbur and Swimming Pool 水题

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

  2. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; &lowbar;A&period; 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 599A】D - 特别水的题4- Patrick and Shopping

    Description  meter long road between his house and the first shop and a d2 meter long road between h ...

  4. 【 CodeForces 604A】B - 特别水的题2-Uncowed Forces

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/B Description Kevin Sun has jus ...

  5. 【CodeForces 606A】A -特别水的题1-Magic Spheres

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/A Description Carl is a beginne ...

  6. 【CodeForces 602A】C - 特别水的题3-Two Bases

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/C Description After seeing the ...

  7. CodeForces 596A Wilbur and Swimming Pool

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

  8. Codeforce&num;331 &lpar;Div&period; 2&rpar; A&period; Wilbur and Swimming Pool&lpar;谨以此题来纪念我的愚蠢&rpar;

    C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  9. Codeforces Round &num;378 &lpar;Div&period; 2&rpar; D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

随机推荐

  1. 将文本文件的内容存储在DataSet中的方法总结

    项目中比较多的会对文件进行操作,例如文件的上传下载,文件的压缩和解压等IO操作.在.NET项目中较多的会使用DataSet,DataTable进行数据的缓存. 项目中对文本文件的操作比较简单,但是如果 ...

  2. Python的由来

    Python的由来 Python这门语言是由C开发而来. C语言: 代码编译得到 机器码 ,机器码在处理器上直接执行,每一条指令控制CPU工作 其他语言: 代码编译得到 字节码 ,虚拟机执行字节码并转 ...

  3. WINDOWS命令和批处理

    转:http://www.cnblogs.com/itech/archive/2009/04/15/1436409.html 另外查看WIndows和Linux的所有命令:http://www.ss6 ...

  4. 判断java中两个对象是否相等

    java中的基本数据类型判断是否相等,直接使用"=="就行了,相等返回true,否则,返回false. 但是java中的引用类型的对象比较变态,假设有两个引用对象obj1,obj2 ...

  5. HTTP和FTP的区别

    原文地址:     http://blog.csdn.net/xiaoxiangzhu660810/article/details/8291656 一.字面上来看 HTTP是Hyper Text Tr ...

  6. 数据库元数据分析Demo

    核心类:DatabaseMetaData.ResultSetMetaData 1 System.err.println("********************************** ...

  7. iOS给自定义个model排序

    今天有朋友问我怎么给Model排序,我顺便写了一个,伸手党直接复制吧. 例如,我建了一个Person类,要按Person的年龄属性排序: Person *per = [[Person alloc] i ...

  8. Python之os&period;fork

    [参考资料] http://www.01happy.com/python-fork-create-process/ http://www.python-course.eu/forking.php ht ...

  9. 最新的 iOS 申请证书与发布流程

    申请流程. 1. 申请钥匙串文件 进入  (Launchpad),找到   (我的是在其他里面找到的),运行后再左上角 存储在桌面就好了,然后就完成退出钥匙串工具就可以了. 2.申请开发证书,发布证书 ...

  10. 【EMV L2】终端风险管理(Terminal Risk Management)

    终端风险管理使大额交易联机授权,并确保芯片交易能够周期性地进行联机以防止在脱机环境中也许无法察觉的风险. 虽然发卡行被强制要求在应用交互特征(AIP)中将终端风险管理位设置成1以触发终端风险管理,但终 ...