题意:给定n(1 <= n <= 4)个矩形的顶点,问能否唯一确定一个矩形。若可以输出矩形面积,否则输出1。
思路:由测试数据就知道,这个矩形一定是平行于坐标轴的,所以只需判断是否存在对立点就可以了。
AC代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-4
#define MAXN (1000+10)
#define MAXM (1000000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 100000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
using namespace std;
int x[4], y[4];
bool judge(int a, int b){
return x[a] != x[b] && y[a] != y[b];
}
int main()
{
int n; Ri(n);
for(int i = 0; i < n; ++i)
Ri(x[i]), Ri(y[i]);
bool flag = false;
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
if(judge(i, j))
{
flag = true;
Pi(abs(x[i]-x[j])*abs(y[i]-y[j]));
break;
}
}
if(flag)
break;
}
if(!flag)
printf("-1\n");
return 0;
}