A -
Wilbur and Swimming Pool

Crawling in process...
Crawling failed
Time Limit:1000MS    
Memory Limit:262144KB    
64bit IO Format:
%I64d & %I64u

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

Sample Output

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个点,判断这n个点能否确定一个矩形,可以的话,输出最大面积,否则输出-1,如果点都在一条直线上那么肯定是不能组成长方形的,每次记录最大最小的横纵坐标就行

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
}p[10];
int main()
{
int n;
while(cin>>n)
{
int x,y,tempx,tempy;
int minx=0x3f3f3f,miny=0x3f3f3f;
int maxx=-0x3f3f3f,maxy=-0x3f3f3f;
for(int i=1;i<=n;i++)
{
cin>>p[i].x>>p[i].y;
minx=min(minx,p[i].x);
maxx=max(maxx,p[i].x);
miny=min(miny,p[i].y);
maxy=max(maxy,p[i].y);
}
if(n==1)
cout<<-1<<endl;
else
{
int ans=(maxx-minx)*(maxy-miny);
if(maxx==minx||maxy==miny)
cout<<-1<<endl;
else
cout<<ans<<endl;
}
}
return 0;
}

Codeforces--596A--Wilbur and Swimming Pool(数学)的更多相关文章

  1. CodeForces 596A Wilbur and Swimming Pool

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

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

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

  4. Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)

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

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

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

  6. CodeForces 596A

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

  7. Codeforces 735C:Tennis Championship(数学+贪心)

    http://codeforces.com/problemset/problem/735/C 题意:有n个人打锦标赛,淘汰赛制度,即一个人和另一个人打,输的一方出局.问这n个人里面冠军最多能赢多少场, ...

  8. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

  9. Codeforces Gym 100002 D"Decoding Task" 数学

    Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

随机推荐

  1. WinServer2008配置任务计划

    window server 2008下配置任务计划 打开window servers 2008下任务计划配置工具 点击“开始”-->“管理工具”-->“任务计划程序”,打开任务计划配置工具 ...

  2. [Windows Server 2008] Serv-U安全设置

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:Serv- ...

  3. 正则表达式提取String子串

    最近遇到了一个字符串处理的功能,忽然发现了正则表达式的强大,深深的被她的迷人魅力所吸引,以前只是听说,今天亲眼所见,亲身经历,真的彻底折服. 言归正传:java中String类里面封装了很多字符串处理 ...

  4. python PIL相关操作

    项目中需要用python生成二维码,这里记录一下相关PIL相关操作. RGBA问题: 需要将图片A粘贴到图片B上,之前没有注意透明度问题,A的背景是透明的,粘贴到B上后,A的周围是黑的.后来才发现是P ...

  5. 我的 Windows 10 的基本配置

    Windows 10 的基本配置 功能性 开启 .Net Framework 3.5(包括 .NET 2.0 和 3.0) 旧版本 Windows 10 默认只安装了 .Net Framework 4 ...

  6. CSS3利用box-shadow实现相框效果

    CSS3利用box-shadow实现相框效果 <style> html { overflow: hidden; background-color: #653845; background- ...

  7. 查找java文件

    想要在eclipse里找一个类文件,可以用快捷键CTRL + SHIFT + R,但是有些文件是jar包里的类文件,可以用下图方法,创建一个变量,然后按住CTRL键,点击类名称 这样就找到jar文件了

  8. 使用python的几个小经验(查看文档)

    好久没有水博客了,未来再过20天不到的时间又得参加软考,今天终于得好好水一发帖子 关于Python,很多人包括我之前都不知道怎么找文档,现在有一个好办法,就是在命令行模式下调用pydoc –p xxx ...

  9. Problem 21

    Problem 21 https://projecteuler.net/problem=21 Let d(n) be defined as the sum of proper divisors of  ...

  10. Spring Cloud 之 Cookie 丢失 与 Host 传递

    通过spring zuul 代理至后台,写入Cookie发现无法写入,到浏览器中,和无法获取Domain域名 通过长时间的度娘和求助别人发现:Spring-zuul  需要加入以下配置 zuul.se ...