CF--A. Wilbur and Swimming Pool
来源:互联网 发布:php开源财务管理系统 编辑:程序博客网 时间:2024/06/03 12:37
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 werenot erased by Wilbur's friend.
Each of the following n lines contains two integersxi andyi ( - 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
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--4) , 最多4个点的横纵坐标,若这些点可以确定一个矩形的话,求其面积 area ,否则输出 -1。
思路:如果是 n==1 ,肯定确定不了一个矩形的;若 n>1,则取其中最小横坐标minx和最小纵坐标miny,最大横坐标maxx和最大纵坐标maxy,若(minx==maxx || miny==maxy)则不构成矩形,输出 -1 ,其它情况计算矩形面积 area。
注意:minx=miny=inf; maxx=maxy=-inf; (看数据范围定)。
code:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define inf 0x3f3f3f3fusing namespace std;int main(){#ifdef OFFLINEfreopen("t.txt","r",stdin);#endifint i, j, k, n;int x[5], y[5], maxx=-inf, maxy=-inf, minx=inf, miny=inf;scanf("%d", &n);if(n==1)printf("-1\n");else{for(i=0;i<n;i++){scanf("%d %d", &x[i], &y[i]);minx=min(minx, x[i]);maxx=max(maxx, x[i]);miny=min(miny, y[i]);maxy=max(maxy, y[i]);}if(maxx==minx||miny==maxy)printf("-1\n");else{int area=abs(maxx-minx)*abs(maxy-miny);printf("%d\n", area);}}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(简单计算)
- 1040. Longest Symmetric String (25)
- 维度模型数据仓库(十六) —— 间接数据源
- Linux常用tool的整理
- spring maven 记录
- Android资源文件-drawable整理
- CF--A. Wilbur and Swimming Pool
- windows 如何查看端口占用情况?
- 早间复盘(2015.11.16)
- spring-boot在jdk1.6下运行web项目
- [Leetcode]Spiral Matrix
- 类与对象
- 博学之,审问之,慎思之,明辨之,笃行之
- MySQL 模糊检索
- HTML的file显示优化处理