zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    前端笔试题目总结——应用JavaScript函数递归打印数组到HTML页面上
    HTM5新增结构化元素&非结构化元素&新增属性详解
    HTML 5 与HTML 4 的区别
    HTML5框架、背景和实体、XHTML的使用规范
    百度前端笔试题目--css 实现一个带尖角的正方形
    HTML5表单提交和PHP环境搭建
    HTML5列表、块、布局
    HTML5 格式化、样式、链接、表格
    2020-09-13助教一周总结(第二周)
    2020-09-10上课小结
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5693397.html
Copyright © 2011-2022 走看看