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 ...
随机推荐
- Android Eclipse 安装教程 2016.06.13版
2016.8.16修改 第一步,也是最为关键的一步——修改hosts文件 为什么说是最关键的一步呢?因为接下来的操作,我们都需要连接google网,也就是要连接国外的网站.一般情况下,国外的网站是无法 ...
- Andorid Scrolling Activity(CoordinatorLayout详情)
1.new project -> Scrolling Activity 2.Layout xml code activity_scrolling.xml <?xml version=&qu ...
- 基于TensorFlow的车牌号识别系统
简介 过去几周我一直在涉足深度学习领域,尤其是卷积神经网络模型.最近,谷歌围绕街景多位数字识别技术发布了一篇不错的paper.该文章描述了一个用于提取街景门牌号的单个端到端神经网络系统.然后,作者阐述 ...
- [Windows Server 2008] 安装网站伪静态
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IIS伪静 ...
- php判断form数据是否为POST而来,判断数据提交方式
//判断form数据是否为POST而来,判断数据提交方式 if ($_SERVER['REQUEST_METHOD'] != 'POST') { // 非 POST 来路,做警告或你想做的事 retu ...
- 从JavaScript的单线程执行说起
先看一段代码: 1 2 3 4 5 setTimeout(function(){ alert("a"); }, 0); while(1); alert("b&qu ...
- Flask 框架构建
Flask 框架构建,目标构建成Django类似的结构 一. 先看看构建后的效果 # 第一次初始化 python manage.py db init # 生成数据库版本 python manage.p ...
- Appium 使用android_uiautomator定位元素时报错: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
使用 android_uiautomator 定位元素时(现在用的还不太熟,对于这个方法还需要加深了解)报错: 报错信息:The requested resource could not be fou ...
- Eclipse安装和使用TFS
第一步下载Tfs插件 去微软官网下载https://www.microsoft.com/en-us/download/details.aspx?id=4240 点击 选择下载 随便放置到一个本地或者服 ...
- 手把手从python安装到setuptools、pip工具安装
一.python安装1.基础开发库 apt-get install gccapt-get install openssl libssl-dev 2.安装数据库和开发库 apt-get install ...