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;
    }
    
  • 相关阅读:
    Spring(十一):Spring配置Bean(四)SpEL
    Java中动态代理方式(使用java.lang.reflect.Proxy实现):
    设计模式(八)静态代理与动态代理模式
    Spring(十):Spring配置Bean(三)Bean的作用域、使用外部属性文件
    如何把本地代码提交到git(码云)、github代码管理项目上
    Spring(九):Spring配置Bean(二)自动装配的模式、Bean之间的关系
    centos7安装mysql5.7
    haproxy(单机)+mysql集群负载均衡
    sql server 用户创建与权限管理
    MySQL之 从复制延迟问题排查
  • 原文地址:https://www.cnblogs.com/hsd-/p/4970302.html
Copyright © 2011-2022 走看看