1020.最小長方形

來源:互聯網
上載者:User

標籤:out   cin   16px   座標軸   用兩個   com   name   用例   family   

題目描述:
    給定一系列2維平面點的座標(x, y),其中x和y均為整數,要求用一個最小的長方形框將所有點框在內。長方形框的邊分別平行於x和y座標軸,點落在邊上也算是被框在內。
輸入:

    測試輸入包含若干測試案例,每個測試案例由一系列座標組成,每對座標佔一行,其中|x|和|y|小於 231;一對0 座標標誌著一個測試案例的結束。注意(0, 0)不作為任何一個測試案例裡面的點。一個沒有點的測試案例標誌著整個輸入的結束。

輸出:

    對每個測試案例,在1行內輸出2對整數,其間用一個空格隔開。第1對整數是長方形框左下角的座標,第2對整數是長方形框右上方的座標。

範例輸入:
12 5623 5613 100 012 340 00 0
範例輸出:
12 10 23 5612 34 12 34
#include<iostream>#include<algorithm>  //用兩個while來保證在讀到兩對0,0的時候跳出來 using namespace std;struct point{    int x;    int y;};point a[100];bool com1(point n,point m){    return n.x<m.x;}bool com2(point n,point m){    return n.y<m.y;}int main(){    int i=0;    while(cin>>a[i].x>>a[i].y && a[i].x!=0 && a[i].y!=0){        i++;        while(cin>>a[i].x>>a[i].y){            if(a[i].x==0 && a[i].y==0) break;            i++;        }        sort(a,a+i,com1);        point n,m;        n.x=a[0].x;        m.x=a[i-1].x;        sort(a,a+i,com2);        n.y=a[0].y;        m.y=a[i-1].y;        cout<<n.x<<" "<<n.y<<" "<<m.x<<" "<<m.y<<endl;        i=0;    }    return 0;}

 

1020.最小長方形

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.