zoukankan      html  css  js  c++  java
  • CF div2 331 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.

    看来只适合做AB。。水题

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <queue>
     5 #include <vector>
     6 #include <stack>
     7 #include <cmath>
     8 
     9 using namespace std;
    10 
    11 const int M = 10005;
    12 const int maxn = 1000000;
    13 typedef long long LL;
    14 
    15 vector<int>G[maxn];
    16 queue<int>Q;
    17 stack<int>st;
    18 
    19 
    20 int a[maxn];
    21 
    22 int main()
    23 {
    24 
    25     int n;
    26     int ans = 0;
    27     scanf("%d",&n);
    28     int x[5],y[5];
    29     for(int i=1;i<=n;i++){
    30         cin>>x[i]>>y[i];
    31     }
    32     if(n == 1) printf("-1
    ");
    33     else if(n == 2) {
    34         if(x[1]!=x[2]&&y[1]!=y[2]){
    35                 ans = abs((x[2]-x[1])*(y[2]-y[1]));
    36             printf("%d
    ",ans);
    37 
    38         }
    39         else printf("-1
    ");
    40     }
    41     else if(n == 3){
    42             int a,b;
    43          if(x[3]!=x[1]) a = abs(x[3] - x[1]);
    44          else a = abs(x[3] - x[2]);
    45          if(y[3] != y[1]) b = abs(y[3]-y[1]);
    46          else b = abs(y[2]-y[1]);
    47         printf("%d
    ",a*b);
    48     }
    49     else if(n == 4){
    50            int a,b;
    51          if(x[3]!=x[1]) a = abs(x[3] - x[1]);
    52          else a = abs(x[3] - x[2]);
    53          if(y[3] != y[1]) b = abs(y[3]-y[1]);
    54          else b = abs(y[2]-y[1]);
    55         printf("%d
    ",a*b);
    56     }
    57     return 0;
    58 }
    View Code
  • 相关阅读:
    Spring中配置文件applicationContext.xml配置详解
    Web.xml配置详解
    linux基础命令学习(七)samba服务器配置
    linux基础命令学习(六)DHCP服务器配置
    linux基础命令学习五(软件包管理、下载管理)
    linux基础命令学习(四)计划任务
    linux上安装php
    linux上安装hadoop
    Redis(二)Jedis操作Redis
    Redis(一)简介及安装、测试
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4979568.html
Copyright © 2011-2022 走看看