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;
    }
    
  • 相关阅读:
    BNUOJ-26474 Bread Sorting 逆序对
    POJ-2480 Longge's problem 积性函数
    Bzoj-2705 Longge的问题 欧拉函数
    Bzoj-2820 YY的GCD Mobius反演,分块
    HDU-4689 Derangement DP
    [转]初学者程序语言的选择
    HDU-4705 Y 树形DP
    HDU-4704 Sum 大数幂取模
    HDU-4699 Editor 数据结构维护
    HDU-4696 Answers 纯YY
  • 原文地址:https://www.cnblogs.com/hsd-/p/4970302.html
Copyright © 2011-2022 走看看