zoukankan      html  css  js  c++  java
  • Codeforces--596A--Wilbur and Swimming Pool(数学)

    
    A - Wilbur and Swimming Pool

    Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    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
    

    Sample Output

    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.

    给了n个点,判断这n个点能否确定一个矩形,可以的话,输出最大面积,否则输出-1,如果点都在一条直线上那么肯定是不能组成长方形的,每次记录最大最小的横纵坐标就行

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct node
    {
    	int x,y;
    }p[10];
    int main()
    {
    	int n;
    	while(cin>>n)
    	{
    		int x,y,tempx,tempy;
    		int minx=0x3f3f3f,miny=0x3f3f3f;
    		int maxx=-0x3f3f3f,maxy=-0x3f3f3f;
    		for(int i=1;i<=n;i++)
    		{
    			cin>>p[i].x>>p[i].y;
    			minx=min(minx,p[i].x);
    			maxx=max(maxx,p[i].x);
    			miny=min(miny,p[i].y);
    			maxy=max(maxy,p[i].y);
    		}
    		if(n==1)
    		cout<<-1<<endl;
    		else
    		{
    			int ans=(maxx-minx)*(maxy-miny);
    			if(maxx==minx||maxy==miny)
    			cout<<-1<<endl;
    			else
    			cout<<ans<<endl;
    		}
    	}
    	return 0;
    }

  • 相关阅读:
    AGC007题解
    博弈论学习笔记
    ZROI2019 提高十连测
    男人八题2019
    LOJ 2840「JOISC 2018 Day 4」糖
    CF671D Roads in Yusland
    网络流套路小结
    BZOJ 3729 GTY的游戏
    AGC036C GP 2
    BZOJ 5046 分糖果游戏
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273397.html
Copyright © 2011-2022 走看看