CodeForces 596A--Wilbur and Swimming Pool
来源:互联网 发布:印度软件 编辑:程序博客网 时间:2024/06/05 03:15
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
20 01 1
1
11 1
-1
题目:给你一个矩形的几个顶点,判断是否能构成矩形,如果可以的话,矩形的面积是多少,不可以的话,输出-1;
ac代码:
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;int main(){int n;int x[5],y[5];bool flag;while(scanf("%d",&n)!=EOF){flag=true;for(int i=1;i<=n;i++){scanf("%d%d",&x[i],&y[i]);}if(n==1){printf("-1\n");continue ;}sort(x+1,x+n+1);sort(y+1,y+n+1);int xa=x[1],xb=x[n];int ya=y[1],yb=y[n];if((xa==xb)||(ya==yb))flag=false;for(int i=1;i<=n;i++){if(x[i]!=xa&&x[i]!=xb){flag=false;break;}if(y[i]!=ya&&y[i]!=yb){flag=false;break;}}int s=(xb-xa)*(yb-ya);if(flag)printf("%d\n",s);elseprintf("-1\n");}return 0;}
- CodeForces 596A--Wilbur and Swimming Pool
- CodeForces 596A-Wilbur and Swimming Pool
- Codeforces 596A 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【水】
- 596A Wilbur and Swimming Pool
- A. Wilbur and Swimming Pool
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool
- CF 596A. Wilbur and Swimming Pool 【计算矩形面积】
- CF--A. Wilbur and Swimming Pool
- cf A. Wilbur and Swimming Pool
- Wilbur and Swimming Pool
- Codeforces Round #331 (Div. 2)A. Wilbur and Swimming Pool(简单计算)
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool (判断组成最大矩形)
- Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
- Linux内核启动分析过程
- css基本语法
- int和Integer的区别
- Java程序中多线程的优先级设置方法
- 把Eclipse工程导入到Android Studio
- CodeForces 596A--Wilbur and Swimming Pool
- 字符串:KMP Eentend-Kmp 自动机 trie图 trie树 后缀树 后缀数组
- HDOJ-2594 Simpsons’ Hidden Talents(KMP)
- 杭电oj 2020 绝对值排序
- 小球反弹问题
- 相同的和
- 相关资料
- html中js实现左边框控制右边框的显示
- 异或运算及其应用