• CodeForces 596A


    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.

    一道签到题,然而我却wa了很多次,我一直以为是让我判断长方形,发现还要输出面积。。。。

     1 #include<iostream>
     2 #include<cmath>
     3 #include<cstdio>
     4 #include<algorithm>
     5 using namespace std;
     6 struct node
     7 {
     8     int x,y;
     9 }a[100];
    10 int main()
    11 {
    12     int n,i,j;
    13     cin>>n;
    14     for(i=1;i<=n;i++)
    15         cin>>a[i].x>>a[i].y;
    16     if(n==1)
    17     {
    18         cout<<"-1"<<endl;
    19     }
    20     else if(n==2)
    21     {
    22         if(a[1].x==a[2].x||a[1].y==a[2].y)
    23         {
    24             cout<<"-1"<<endl;
    25         }
    26         else
    27             cout<<abs(a[1].x-a[2].x)*abs(a[2].y-a[1].y)<<endl;
    28     }
    29     else
    30     {
    31         for(i=1;i<=n;i++)
    32         {
    33             for(j=1;j<=n;j++)
    34             {
    35                 if(a[i].x!=a[j].x&&a[i].y!=a[j].y)
    36                 {
    37                     cout<<abs(a[i].x-a[j].x)*abs(a[i].y-a[j].y)<<endl;
    38                     return  0;
    39                 }
    40             }
    41         }
    42         cout<<"-1"<<endl;
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    Docker 使用Docker创建MySQL容器
    Javascript 转Date对象为字符串实现函数
    Jenkins 实现Gitlab事件自动触发Jenkins构建及钉钉消息推送
    Sysbench 使用总结
    ElementUI Dialog 结合Vue实现对话框body“二分”布局
    Element FORM结合Vue实现横向排列表单项
    Vue 插槽之插槽内容学习总结
    Vue 基于VSCode结合Vetur+ESlint+Prettier统一Vue代码风格
    Pytest Pytest源码分析
    Vue 中引用第三方js总结
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5693397.html
Copyright © 2020-2023  润新知