zoukankan      html  css  js  c++  java
  • Codeforces Round #331 (Div. 2) A

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

    题意 给你n个点 n<=4 保证是矩形的顶点  求矩形的面积

    很水的一道题目 题意看懂 就可以

    要不是我挂了综测 我是不会 贴的

    作死排了个序 沙雕

    #include<bits/stdc++.h>
    using namespace std;
    int n;
    struct node
    {
        int x;
        int y;
    }N[5];
    int main()
    {
        scanf("%d",&n);
        memset(N,0,sizeof(N));
        for(int i=0;i<n;i++)
            scanf("%d%d",&N[i].x,&N[i].y);
        if(n<2)
            {
            printf("-1
    ");
            return 0;
            }
        if(n==2)
        {
            if(N[0].x!=N[1].x&&N[0].y!=N[1].y)
                printf("%d
    ",abs((N[1].x-N[0].x)*(N[1].y-N[0].y)));
            else
                printf("-1
    ");
            return 0;
        }
        for(int i=1;i<n;i++)
        {
            if(N[0].x!=N[i].x&&N[0].y!=N[i].y)
            {
            printf("%d
    ",abs((N[i].x-N[0].x)*(N[i].y-N[0].y)));
             return 0;
            }
        }
        for(int i=0;i<n;i++)
        {
            if(N[1].x!=N[i].x&&N[1].y!=N[i].y)
            {
            printf("%d
    ",abs((N[i].x-N[1].x)*(N[i].y-N[1].y)));
           return 0;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    精选的一些《编程之美》相关资料
    使用SftpDrive+SourceInsight阅读开源代码
    malloc()参数为0的情况
    《编程之美》4.5磁带文件存放优化:最优解是怎样炼成的
    从《编程之美》买票找零问题说起,娓娓道来卡特兰数——兼爬坑指南
    《编程之美》3.6判断链表是否相交之扩展:链表找环方法证明
    解答《编程之美》1.18问题1:给所有未标识方块标注有地雷概率
    C语言中 Float 数据结构的存储计算
    C#之内存分配
    unity----------------3D模型讲解
  • 原文地址:https://www.cnblogs.com/hsd-/p/4970302.html
Copyright © 2011-2022 走看看