Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题
A. Wilbur and Swimming Pool
Time Limit: 20 Sec
Memory Limit: 256 MB
題目連接
http://codeforces.com/contest/596/problem/A
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 0
1 1
Sample Output
1HINT
?
題意
一個矩形,4個點,但是被人擦去了,現在就只有n個點了
然后問你這n個點能不能構成獨一無二的矩形,如果可以輸出面積
否則否則輸出-1
題解:
掃一遍四個點,判斷minx==maxx miny==maxy,滿足兩個中的一個,就輸出-1
否則輸出面積就好了
代碼
#include<iostream> #include<stdio.h> #include<algorithm> using namespace std;int main() {int n;cin>>n;int minx,maxx,miny,maxy;cin>>minx>>miny;maxx=minx,maxy=miny;if(n==1)return puts("-1");for(int i=1;i<n;i++){int x,y;cin>>x>>y;minx=min(minx,x);maxx=max(maxx,x);miny=min(miny,y);maxy=max(maxy,y);}if((maxx==minx)||(maxy==miny))return puts("-1");printf("%d\n",(maxx-minx)*(maxy-miny)); }?
轉載于:https://www.cnblogs.com/qscqesze/p/4967947.html
總結
以上是生活随笔為你收集整理的Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 个人阅读作业Week7
- 下一篇: elang 安装