CodeForces 596A
2016-03-19 13:35
357 查看
A - Wilbur and Swimming Pool
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
Input
Output
Input
Output
//解题思路:给出n个点的坐标,计算包含这几个点的最小水池的面积,sort()排序出x轴的最长距离,y轴的最长距离,然后求出矩形面积就行
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n;
int x[1010],y[1010];
while (scanf ("%d",&n)!=EOF)
{
for (int i=0;i<n;i++)
scanf ("%d%d",&x[i],&y[i]);
sort(x,x+n);
sort(y,y+n);
int dx=x[n-1]-x[0];
int dy=y[n-1]-y[0];
long long sum=dx*dy;
if (sum)
printf ("%lld\n",sum);
else
printf ("-1\n");
}
return 0;
}
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
Input
2 0 0 1 1
Output
1
Input
11 1
Output
-1
//解题思路:给出n个点的坐标,计算包含这几个点的最小水池的面积,sort()排序出x轴的最长距离,y轴的最长距离,然后求出矩形面积就行
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n;
int x[1010],y[1010];
while (scanf ("%d",&n)!=EOF)
{
for (int i=0;i<n;i++)
scanf ("%d%d",&x[i],&y[i]);
sort(x,x+n);
sort(y,y+n);
int dx=x[n-1]-x[0];
int dy=y[n-1]-y[0];
long long sum=dx*dy;
if (sum)
printf ("%lld\n",sum);
else
printf ("-1\n");
}
return 0;
}
相关文章推荐
- JS的魅力
- 【转】Fiddler的基本介绍
- TFS 10周年生日快乐 – TFS与布莱恩大叔的故事
- java.util.Stack类中的peek()方法
- 四则运算终结版
- codeforces 655C C. Enduring Exodus(二分)
- 给button添加点击事件,打开一个新的窗体
- make警告:检测到时钟错误
- Delphi常见图象格式转换技术
- java编程思想-字符串
- IOS CALayer(一)
- 计算机网络_面试
- MySQL 新增库同步到Slave
- 【java算法】约瑟夫问题求解
- Win10无法上网提示缺少一个或者多个网络协议的处理方法
- java正则表达式语法
- 【matlab】:matlab中 RGB到YUV的转变
- win7中安装jdk/mysql/odbc
- 搭建Cordova + Ionic + WebStorm环境开发Web App应用
- GitHub: 终端上传项目