最小长方形

题目描述:
    给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内。长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内。
输入:

    测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于 231;一对0 坐标标志着一个测试用例的结束。注意(0, 0)不作为任何一个测试用例里面的点。一个没有点的测试用例标志着整个输入的结束。

输出:

    对每个测试用例,在1行内输出2对整数,其间用一个空格隔开。第1对整数是长方形框左下角的坐标,第2对整数是长方形框右上角的坐标。

样例输入:
12 56
23 56
13 10
0 0
12 34
0 0
0 0
样例输出:
12 10 23 56
12 34 12 34

 1 #include <cstdlib>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <cctype>
 6 
 7 #include <iostream>
 8 #include <string>
 9 #include <vector>
10 #include <list>
11 #include <deque>
12 #include <set>
13 #include <map>
14 #include <stack>
15 #include <queue>
16 #include <algorithm>
17 
18 #define MAXN 100001
19 #define MAXD 99999999
20 using namespace std;
21 
22 int main()
23 {
24 
25     int l,r,top,bottom;
26 
27     int x,y;
28 
29     while(scanf("%d%d",&x,&y)!=EOF)
30     {
31         if((x==0)&&(y==0))
32             break;
33 
34         l=r=x;
35         top=bottom=y;
36 
37 
38         while(scanf("%d%d",&x,&y)!=EOF)
39         {
40             if((x==0)&&(y==0))
41                 break;
42 
43 
44             if(l>x)
45             {
46                 l=x;
47             }
48 
49             if(r<x)
50             {
51                 r=x;
52             }
53 
54             if(y>top)
55             {top=y;}
56 
57             if(y<bottom)
58             {
59                 bottom=y;
60             }
61 
62         }
63 
64 
65         printf("%d %d %d %d\n",l,bottom,r,top);
66     }
67 
68 
69     
70     
71    
72   
73     return 0;
74 }

 

posted @ 2012-05-30 20:24  cseriscser  阅读(338)  评论(0编辑  收藏  举报