• 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;
    }

  • 相关阅读:
    例题3-6 环状序列UVa1584
    习题3-1 Score UVa1585
    Sublime Text3 Python虚拟环境(补充)——解决控制台中文乱码情况
    Cookie保存在本地方法介绍
    Multisim仿真
    小米手机安装charles证书
    【转】缓存
    【转】5种网络IO模型
    【转】分布式锁的几种使用方式(redis、zookeeper、数据库)
    【转】白话解析:一致性哈希算法(consistent hashing)
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273397.html
Copyright © 2020-2023  润新知