Codeforces--596A--Wilbur and Swimming Pool(数学)
Wilbur and Swimming Pool
Crawling in process...
Crawling failed
Time 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 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
2
0 0
1 1
1
1
1 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;
else
cout<<ans<<endl;
}
}
return 0;
}
Codeforces--596A--Wilbur and Swimming Pool(数学)的更多相关文章
- CodeForces 596A Wilbur and Swimming Pool
水题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...
- 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/conte ...
- Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)
C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...
- 【CodeForces 596A】E - 特别水的题5-Wilbur and Swimming Pool
Description After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the ...
- CodeForces 596A
Description After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the ...
- Codeforces 735C:Tennis Championship(数学+贪心)
http://codeforces.com/problemset/problem/735/C 题意:有n个人打锦标赛,淘汰赛制度,即一个人和另一个人打,输的一方出局.问这n个人里面冠军最多能赢多少场, ...
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- Codeforces Gym 100002 D"Decoding Task" 数学
Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...
随机推荐
- (转)Hibernate关联映射——一对多(多对一)
http://blog.csdn.net/yerenyuan_pku/article/details/70152173 Hibernate关联映射——一对多(多对一) 我们以客户(Customer)与 ...
- Codeforces_732D_(二分贪心)
D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- iOS标准库中常用数据结构和算法之查找
参数: key: [in] 要查找的元素.base:[in] 数组元素的首地址.nelp: [in/out] 数组的元素个数指针.width: [in] 数组中每个元素的尺寸.compar: [in] ...
- enote笔记语言(4)(ver0.4)——“5w1h2k”分析法
章节:“5w1h2k”分析法 what:我想知道某个“关键词(keyword)”(即,词汇.词语,或称单词,可以是概念|专业术语|.......)的定义. why:我想分析and搞清楚弄明白“事物 ...
- TCP/IP UDP 协议首部及数据进入协议栈封装的过程
数据的封装 UDP 封装 TCP 封装 IP 封装 检验和算法 当应用程序用TCP传送数据时,数据被传送入协议栈中,然后逐一通过每一层直到被当作一串比特流送入网络 注: UDP数据TCP数据基本一致. ...
- django访问静态变量的设置
在项目的urls.py文件中 默认urlpatterns是空的列表需要填入url匹配的路由,默认使用static from django.conf.urls import include, url f ...
- SqlServer转换为Mysql(mss2sql)
SqlServer转换为Mysql(mss2sql)工具 http://pan.baidu.com/s/1c2d8R8O 参考链接: http://www.cnblogs.com/angestudy/ ...
- 【codeforces 527A】Playing with Paper
[题目链接]:http://codeforces.com/contest/527/problem/A [题意] 让你每次从一个长方形里面截出一个边长为长方形的较短边的正方形; 然后留下的部分重复上述步 ...
- POJ - 3538 - Domestic Networks
先上题目: Domestic Networks Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 732 Accepted: ...
- ZOJ - 2243 - Binary Search Heap Construction
先上题目: Binary Search Heap Construction Time Limit: 5 Seconds Memory Limit: 32768 KB Read the sta ...