Problem Link:http://139.129.36.234/problem.php?id=1206
1206: 最小长方形
时间限制: 1 Sec 内存限制: 32 MB提交: 5 解决: 3
[ 提交][ 状态][ 讨论版]
题目描述
给定一系列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
提示
来源
AC code:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<math.h>
#include<string.h>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<set>
#define LL long long
#define exp 1e-9
#define MAXN 1000010
using namespace std;
int main()
{
// freopen("D:\\in.txt","r",stdin);
int x,y,minx,miny,maxx,maxy;
while(scanf("%d%d",&x,&y)!=EOF)
{
if(x==0 && y==0)
{
break;
}
minx=maxx=x;
miny=maxy=y;
while(1)
{
scanf("%d%d",&x,&y);
if(x==0 && y==0)
break;
minx=min(minx,x);
miny=min(miny,y);
maxx=max(maxx,x);
maxy=max(maxy,y);
}
printf("%d %d %d %d\n",minx,miny,maxx,maxy);
}
return 0;
}