【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 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
2
0 0
1 1
1
1
1 1
-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的更多相关文章
- 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 ...
- 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 ...
- 【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 ...
- 【 CodeForces 604A】B - 特别水的题2-Uncowed Forces
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/B Description Kevin Sun has jus ...
- 【CodeForces 606A】A -特别水的题1-Magic Spheres
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/A Description Carl is a beginne ...
- 【CodeForces 602A】C - 特别水的题3-Two Bases
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/C Description After seeing the ...
- CodeForces 596A Wilbur and Swimming Pool
水题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...
- 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 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
随机推荐
- CSS3实现气泡效果
首先定义一个 <p class="speech"></p> 先给外层的容器添加样式: p.speech { position: relative; widt ...
- UESTC 912 树上的距离 --LCA+RMQ+树状数组
1.易知,树上两点的距离dis[u][v] = D[u]+D[v]-2*D[lca(u,v)] (D为节点到根节点的距离) 2.某条边<u,v>权值一旦改变,将会影响所有以v为根的子树上的 ...
- linux下的缓存机制及清理buffer/cache/swap的方法梳理
(1)缓存机制 为了提高文件系统性能,内核利用一部分物理内存分配出缓冲区,用于缓存系统操作和数据文件,当内核收到读写的请求时,内核先去缓存区找是否有请求的数据,有就直接返回,如果没有则通过驱动程序直接 ...
- 纯CSS3制作皮卡丘动画壁纸
前言 明天就放假了,趁着今晚的空挡时间来写这篇博客——这是我昨晚实现的一个简单的CSS3动画效果.话说还得缘起我逛了一下站酷网,然后不小心看到了一张皮卡丘的手机壁纸,觉得很可爱,然后觉得这种效果是可以 ...
- PHP mcrypt加密扩展使用总结
在开发中,很多时候我们在前后端交互中需要对一些敏感数据进行一定的加密.PHP中有提供了mcrypt的这样一个加密扩展实现对数据的加密解密. 一.mcrypt扩展的安装 在低版本的PHP中需要在配置文件 ...
- 02SpringMvc_springmvc快速入门小案例(XML版本)
这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC. 先给出整个项目的结构图:
- [转]redis.conf的配置解析
# redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k => 1000 bytes # 1kb ...
- Python自动化测试 (二) ConfigParser模块读写配置文件
ConfigParser 是Python自带的模块, 用来读写配置文件, 用法及其简单. 直接上代码,不解释,不多说. 配置文件的格式是: []包含的叫section, section 下有op ...
- Log4Net写入到数据库配置过程中的一些小问题备忘
问题1: 在公司进行log4net写入服务器配置的时候,一切正常,但是在家里的机器上,就频繁出现这个问题: SQL Server 2008 报错:已成功与服务器建立连接,但是在登录前的握手期间发生错误 ...
- JS 之原型,实例,构造函数之间的关系
JS是面向对象的语言,函数也是对象.下面大致介绍下实例,原型与构造函数之间的关系. 构造函数模式 function Person(name,age){ this.name = name; this.a ...