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. 论文deadline 最后三天

    2015.12.29 星期二 内容整改 2015.12.30 星期三 参考文献,摘要等 2015.12.31 星期四 最后修改 尽最大的努力去做好论文的事情.

  2. R语言数据重塑

    使用cbind()函数连接多个向量来创建数据帧.此外,使用rbind()函数合并两个数据帧   使用merge()函数合并两个数据帧.数据帧必须具有相同的列名称,在其上进行合并   melt()拆分数 ...

  3. Spring Boot 集成 JWT 实现单点登录授权

    使用步骤如下:1. 添加Gradle依赖: dependencies { implementation 'com.auth0:java-jwt:3.3.0' implementation('org.s ...

  4. Xilinx FPGA的专用时钟引脚及时钟资源相关

    主要参考了https://www.eefocus.com/liu1teng/blog/12-02/237897_4533d.html .Xilinx UG471.UG472以及Xilinx Forum ...

  5. DOM节点的获取

      document.getElementById();//id名,在实际开发中较少使用,选择器中多用class  id一般只用在顶级层存在 不能太过依赖id document.getElements ...

  6. Coefficient Computation (大整数、Java解决)

    Coefficient Computation UVALive8265 题意:计算组合数C(n,k)的值并将值按给定的进制输出. 思路:Java大整数类硬上. PS:刚刚学完Java的大整数类,结果却 ...

  7. php 导出Excel 不用安装插件、开启配置

    function export_csv($filename, $data) { header("Content-type:text/csv"); header("Cont ...

  8. MySQL数据库操作(一)

    一.数据操作 1.显示数据库 show databases; 2.创建数据库 #utf- create database 数据库名称 default charset utf8 collate utf8 ...

  9. 6.3.1 使用 pickle 模块读写二进制文件

    Python 标准库 pickle 提供的 dump() 方法 用于将数据进行序列化并写入文件(dump() 方法的protocol 参数为True 时可以实现压缩的效果),而load() 用于读取二 ...

  10. unigui菜单【3】

    unigui菜单TuniTreeView 根据数据库表中的内容,显示菜单的处理: function TMainForm.CreateMenu: Integer; var myMenuPoint : P ...