Codeforces--596A--Wilbur and Swimming Pool(数学)
来源:互联网 发布:php租车系统源码 编辑:程序博客网 时间:2024/06/05 05:26
Crawling in process...Crawling failedTime Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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 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.
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
Sample Output
Hint
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个点,判断这n个点能否确定一个矩形,可以的话,输出最大面积,否则输出-1,如果点都在一条直线上那么肯定是不能组成长方形的,每次记录最大最小的横纵坐标就行
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;struct node{int x,y;}p[10];int main(){int n;while(cin>>n){int x,y,tempx,tempy;int minx=0x3f3f3f,miny=0x3f3f3f;int maxx=-0x3f3f3f,maxy=-0x3f3f3f;for(int i=1;i<=n;i++){cin>>p[i].x>>p[i].y;minx=min(minx,p[i].x);maxx=max(maxx,p[i].x);miny=min(miny,p[i].y);maxy=max(maxy,p[i].y);}if(n==1)cout<<-1<<endl;else{int ans=(maxx-minx)*(maxy-miny);if(maxx==minx||maxy==miny)cout<<-1<<endl;elsecout<<ans<<endl;}}return 0;}
- Codeforces--596A--Wilbur and Swimming Pool(数学)
- CodeForces 596 A 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 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
- 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
- CF 596 A Wilbur and Swimming Pool(判断能否唯一确定矩形/set)
- SQOOP --hive-import 错误(Sqoop Hive exited with status 1)及解决
- 李白打酒
- DLP
- ubuntu操作系统安装(三) 更改软件源
- OGC
- Codeforces--596A--Wilbur and Swimming Pool(数学)
- 蓝桥杯单片机设计与开发笔记(二)
- ArrayList Vector LinkedList 区别与用法
- 矩阵乘法
- 剑指offer-连续子数组的最大和----编程之美-连续子数组的最大和
- Linux笔记(22)——挂载分区
- Arcgis
- su 和 sudo的区别
- xUtils更新到3.0后的基本使用规则