【Codeforces Round 331 (Div 2)A】【水题】Wilbur and Swimming Pool 给出矩形1~4个顶点让你还原矩形

原创 2015年12月03日 21:53:56
Wilbur and Swimming Pool
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
input
2
0 0
1 1
output
1
input
1
1 1
output
-1
Note

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.


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int x[4];
int y[4];
int n;
int main()
{
	while(~scanf("%d",&n))
	{
		int maxx=-1e9;
		int minx=1e9;
		int maxy=-1e9;
		int miny=1e9;
		for(int i=1;i<=n;++i)
		{
			scanf("%d%d",&x[i],&y[i]);
			gmax(maxx,x[i]);
			gmax(maxy,y[i]);
			gmin(minx,x[i]);
			gmin(miny,y[i]);
		}
		int ans=(maxx-minx)*(maxy-miny);
		if(ans==0)ans=-1;
		printf("%d\n",ans);
	}
	return 0;
}
/*
【trick&&吐槽】
我用%d输出LL,竟然还是AC了!好感动!也好不小心啊!

【题意】
我们有一个矩形。
现在告诉你这个矩形的n(1<=n<=4)个点,问你,我们能否还原这个矩形。

【类型】
水题

【分析】
你还打算讨论?噗!
其实我们只要看看我们能否找出矩形的左下角和右上角, 求出其面积就好啦!

*/

版权声明:题解中哪里写错请一定要指出来QwQ 转载还请注明下出处哦,谢谢^_^

相关文章推荐

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 megab...

Codeforces Round #331 (Div. 2)-Wilbur and Swimming Pool(模拟)

A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megab...

【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b

Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes ...

CF 596 A Wilbur and Swimming Pool(判断能否唯一确定矩形/set)

题目链接: CF 596 A Wilbur and Swimming Pool 题意: 给n个点,问能不能唯一确定一个矩形,可以的话输出矩形面积,否则输出-1。#include #includ...
  • Ramay7
  • Ramay7
  • 2016年04月10日 22:59
  • 190

Codeforces Round #331 (Div. 2) C. Wilbur and Points 贪心+排序

题目~~ 题意: 有n个坐标,wi为(yi-xi),再给出n个wj(j=0~n), wi==wj 则第i个坐标标号为j,而满足xi...

【Codeforces Round 331 (Div 2)C】【脑洞 SET贪心写法】Wilbur and Points 锯齿图形差值编号,右上角的最大

Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input stan...

Codeforces Round #331 (Div. 2) C. Wilbur and Points

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandar...

Codeforces Round #331 (Div. 2)——C. Wilbur and Points

MD,又因为一个傻逼错误搞了一个下午+一个晚上。。忧桑= = 题意: 现在有n个点,然后给出n个点的x,y坐标。然后这些坐标必须满足条件:比如说分配给点(x,y)的标号是i,那么点(x',y')的标号...

Codeforces Round #385 (Div. 2) -- B. Hongcow Solves A Puzzle (判断是否是矩形,水题)

大体题意: 给你一个n*m 的矩阵,  你要用两个同样的图形构造出一个矩形来,问是否可以?   .表示 这个地方是空地,X表示是一个小元素!你不可以旋转覆盖, 只能移动整体! 思路: 这个题意一开始理...

CodeForces 596A-Wilbur and Swimming Pool

After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:【Codeforces Round 331 (Div 2)A】【水题】Wilbur and Swimming Pool 给出矩形1~4个顶点让你还原矩形
举报原因:
原因补充:

(最多只允许输入30个字)