【Virtual Judge】E - 特别水的题5-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

2
0 0
1 1

Output

1

Input

1
1 1

Output

-1

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为1、2、34的情况,x=3或者4时用循环找出x,y坐标不同的两点,面积要绝对值,代码不写了。

或者不要讨论,直接在读入的时候,找出x,y的最大值和最小值,计算面积如果面积==0,,那就输出-1,代码如下:

#include<stdio.h>
#include<algorithm>
using namespace std;
long long n,area,xmin=1001,ymin=1001,xmax=-1001,ymax=-1001;
struct Node
{
    long long x,y;
} node[5];
int main()
{
    scanf("%lld",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld%lld",&node[i].x,&node[i].y);
        xmax=max(xmax,node[i].x);
        xmin=min(xmin,node[i].x);
        ymax=max(ymax,node[i].y);
        ymin=min(ymin,node[i].y);
    }
    area=(ymax-ymin)*(xmax-xmin);
    if(area)printf("%lld\n",area);
    else printf("-1\n");
    return 0;
}

  

时间: 2024-10-24 10:39:54

【Virtual Judge】E - 特别水的题5-Wilbur and Swimming Pool的相关文章

专题一、简单搜索 - Virtual Judge

很久以前刷完了Virtual Judge上的简单搜索专题,现总结如下: POJ 1321 由于题目的数据范围比较小,可以直接dfs暴力.读入时记录每个空位的位置,保存在pX[]以及pY[]数组中.暴力的时候统计当前处理第几个空格以及当前处理到了第几行即可. #include <iostream> #include <memory.h> using namespace std; const int MAX = 128; long long ans; int N, K, nCnt; b

Ubuntu 14.04 Virtual Judge 的搭建

Ubuntu 14.04 Virtual Judge 的搭建 博客的排版可能不是很好,可以下载本文的PDF: Ubuntu 14.04Virtual Judge 的搭建 本人是一名ACM弱菜,由于集训队需要, 我们决定架设自己的OnlineJudge和Virtual Judge,于是开始了噩梦般的搭建. OJ的搭建,非常顺利,参考的是 Ubuntu Server 12.04搭建hustoj 这篇博客 写得非常好,其他不多说,如果有需要搭建自己学校的OJ的朋友,可以参考, 主要就是架设LAMP,其

Virtual Judge使用指南

https://cn.vjudge.net/ Virtual Judge并不是常规的Online Judge平台,他通过爬取其他OJ的题目,让我们可以直接在VJ上查找并提交各种OJ的题目,然后将我们的题目通过他的账号(比如你在cf上会看到用户名vj1.vj2--在HDU上会看到张翼德.马孟起--)在真正的OJ上提交并把结果反馈给我们.大概就相当于一个平台一个中介吧.貌似ACM选手使用得较为普遍? 右上角注册登录: 界面这些OJ是他可以爬到题目的,也就是我们可以直接在VJ里做题的.每个图标也可以直

HDU-1037-Keep on Truckin&#39;(HDU最水的题没有之一,为了练英语就来吧)

Keep on Truckin' Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10324    Accepted Submission(s): 7147 Problem Description Boudreaux and Thibodeaux are on the road again . . . "Boudreaux, we ha

【Virtual Judge】G - 一般水的题2-Approximating a Constant Range

Description When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number o

【Virtual Judge】H - 大概做不来的题 Approximating a Constant Range

Description In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and yif and onl

8.2/baltic神(水)题

bzoj1334: Description N个政党要组成一个联合内阁,每个党都有自己的席位数. 现在希望你找出一种方案,你选中的党的席位数要大于总数的一半,并且联合内阁的席位数越多越好. 对于一个联合内阁,如果某个政党退出后,其它党的席位仍大于总数的一半,则这个政党被称为是多余的,这是不允许的. Input 第一行给出有多少个政党.其值小于等于300 下面给出每个政党的席位数.总席位数小于等于 100000 Output 你的组阁方案中最多能占多少个席位. 背包dp.一开始想着贪心贪心...后

virtual judge(专题一 简单搜索 B)

Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot m

HDU 1013Digital Roots 吃完饭,水个题。

Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 53073    Accepted Submission(s): 16565 Problem Description The digital root of a positive integer is found by summing the digits of