CF 596A. Wilbur and Swimming Pool 【计算矩形面积】
2016-03-17 16:27
435 查看
A. Wilbur and Swimming Pool
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
output
input
output
Note
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.
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
2 0 0 1 1
output
1
input
11 1
output
-1
Note
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.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <queue> #include <stack> #include <algorithm> #define W(a) while((a)--) #define Si(a) scanf("%d", &a) #define Sl(a) scanf("%lld", &a) #define Pi(a) printf("%d\n", (a)) #define Pl(a) printf("%lld\n", (a)) #define CLR(a, b) memset(a, (b), sizeof(a)) #define INF 0x3f3f3f3f #define LL long long using namespace std; int main() { int n; while(Si(n)==1) { int maxx = -INF, maxy = -INF; int minx = INF, miny = INF; int x, y; for(int i = 0; i < n; ++i) { scanf("%d%d", &x, &y); maxx = max(maxx, x); minx = min(minx, x); maxy = max(maxy, y); miny = min(miny, y); } LL s; s = (maxx-minx)*(maxy-miny); if(s==0) s = -1; Pl(s); } return 0; }
相关文章推荐
- Double click 转成power之后的上报
- poj1328 radar installation
- Java循环基础
- do { x } while (__LINE__ == -1)
- 计算前50个素数
- [leetcode] @python 115. Distinct Subsequences
- .net4.0调用非托管DLL的异常捕获
- sed 递归替换
- 学习英语
- 【编程工具】MyEclipse中的常用快捷键
- spring mvc3 静态文件放在WEB-INF下无法访问解决和解决@Controller失效问题
- python 刷题:实现队列
- Servlet映射的匹配原则,优先级
- uva 10954 add all
- IOS-57-导致内存未释放的常见原因(现象:dealloc不执行等)
- 牛顿下山法
- BB-Black: 如何擦除emmc里的内容?
- nginx tomcat 负载均衡
- 学习之spring属性文件注入
- Java流操作之转换流