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/contest/596/problem/A
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
Sample Output
1
HINT
题意
一个矩形,4个点,但是被人擦去了,现在就只有n个点了
然后问你这n个点能不能构成独一无二的矩形,如果可以输出面积
否则否则输出-1
题解:
扫一遍四个点,判断minx==maxx miny==maxy,满足两个中的一个,就输出-1
否则输出面积就好了
代码
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std; int main()
{
int n;cin>>n;
int minx,maxx,miny,maxy;
cin>>minx>>miny;
maxx=minx,maxy=miny;
if(n==)return puts("-1");
for(int i=;i<n;i++)
{
int x,y;cin>>x>>y;
minx=min(minx,x);
maxx=max(maxx,x);
miny=min(miny,y);
maxy=max(maxy,y);
}
if((maxx==minx)||(maxy==miny))
return puts("-1");
printf("%d\n",(maxx-minx)*(maxy-miny));
}
Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题的更多相关文章
- 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 Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题
C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...
- 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 #185 (Div. 2) A. Whose sentence is it? 水题
A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题
A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...
- Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题
A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题
B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...
- 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 ...
随机推荐
- Android 超仿Path时间轴和扇形菜单的效果
网上看到的 ,仅此记录一下,用到的时候便于查找 效果如下: 源码下载地址 : http://download.csdn.net/detail/abc13939746593/7251933
- 【转】IOS NSTimer 定时器用法总结
原文网址:http://my.oschina.net/u/2340880/blog/398598 NSTimer在IOS开发中会经常用到,尤其是小型游戏,然而对于初学者时常会注意不到其中的内存释放问题 ...
- UTF-8编码规则
UTF-8是Unicode的一种实现方式,也就是它的字节结构有特殊要求,所以我们说一个汉字的范围是0X4E00到0x9FA5,是指unicode值,至于放在utf-8的编码里去就是由三个字节来组织,所 ...
- ASP.NET MVC+Bootstrap个人博客之后台dataTable数据列表(五)
jQuery dataTables 插件是一个优秀的表格插件,是后台工程师的福音!它提供了针对数据表格的排序.浏览器分页.服务器分页.查询.格式化等功能.dataTables 官网也提供了大量的演示 ...
- Slalom
题意: 有n个宽度为w的门,给出门的左端点的水平位置x和高度y,和恒定的垂直速度,现有s个速度,求能通过这n个门的最大速度. 分析: 二分速度判断 #include <map> #incl ...
- Codeforces 372
A (被装的袋鼠不可以装的袋鼠)贪心,排序,从n/2分成两部分. B 好一道前缀和的题目. C 标准算法不难想,m^2的算法见http://codeforces.com/blog/entry/9907 ...
- RabbitMQ>Erlang machine stopped instantly (distribution name conflict?). The service is not restarted as OnFail is set to ignore.-报错解决方案 原来是NNND。。。
>Erlang machine stopped instantly (distribution name conflict?). The service is not restarted as ...
- 一些常用的IOS开发网站
开发教程: 即便过了入门阶段,还是要经常看看一些不错的实例教程.1.http://mobile.tutsplus.com/category/tutorials/iphone/ 比较新的一个网站,以前没 ...
- HDU 5816 Hearthstone (状压DP)
Hearthstone 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an onlin ...
- POJ 2240 Arbitrage (求负环)
Arbitrage 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/I Description Arbitrage is the ...