cf A. Wilbur and Swimming Pool
来源:互联网 发布:剑灵女枪手捏脸数据图 编辑:程序博客网 时间:2024/06/04 19:21
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.
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.
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
20 01 1
1
11 1
-1
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<queue>#include<stack>#include<cmath>using namespace std;typedef long long ll;int x[5],y[5];int main(){int n,i,j;int ans;cin>>n;for(i=1;i<=n;i++) cin>>x[i]>>y[i];if(n==1) cout<<"-1"<<endl;else if(n==2) {if(x[1]==x[2]||y[1]==y[2]) cout<<"-1"<<endl;else {ans=(x[1]-x[2])*(y[1]-y[2]);if(ans<0) ans=-ans;cout<<ans<<endl;}}else {sort(x+1,x+1+n); sort(y+1,y+1+n); ans=(x[1]-x[3])*(y[1]-y[3]); if(ans<0) ans=-ans; cout<<ans<<endl;}return 0;}
- CF--A. Wilbur and Swimming Pool
- cf A. Wilbur and Swimming Pool
- A. Wilbur and Swimming Pool
- CF 596A. Wilbur and Swimming Pool 【计算矩形面积】
- 596A Wilbur and Swimming Pool
- CodeForces 596A--Wilbur and Swimming Pool
- CodeForces 596A-Wilbur and Swimming Pool
- Wilbur and Swimming Pool
- CF 596 A Wilbur and Swimming Pool(判断能否唯一确定矩形/set)
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
- Codeforces 596A Wilbur and Swimming Pool 【水题】
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
- Codeforces--596A--Wilbur and Swimming Pool(数学)
- CodeForces - 596A Wilbur and Swimming Pool (模拟)
- CodeForces 596 A Wilbur and Swimming Pool【数学】
- CodeForces 596A:Wilbur and Swimming Pool【水】
- Wilbur and Swimming Pool(矩形求面积)
- Codeforces Round #331 (Div. 2)A. Wilbur and Swimming Pool(简单计算)
- TinyOS的个人见解3之make
- 遇到错误javax.el.PropertyNotFoundException: Property 'start' not found on type java.lang.String
- 把网站从vps转移到虚拟主机后伪静态不能从
- 支持向量机SVM——LIBSVM
- 黑马程序员——Java基础---面向对象
- cf A. Wilbur and Swimming Pool
- Android studio小技巧之xml与Java类快速跳转
- 多线程Runtime.getRuntime().exec常见问题
- Oracle trunc()函数的用法
- 如何在C语言中调用shell命令
- 实时推荐系统的3种方式
- 三种素数筛选方法
- ppt制作
- 用Javascript编写Chrome浏览器插件--(一)