题目:
给定一系列2维平面点的坐标(x,y),其中x和y均为整数,要求用一个最小的长方形框将所有的点框在内,长方形框的边分别平行与x和y坐标轴,点落在边上也算是被框在内
输入描述:
测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于231;一对0坐标标志着一个测试用例的结束。注意(0,0)不作为任何一个测试用例里面的点。一个没有点的测试用例标志着整个输入的结束。
输出描述:
对每个测试用例,在一行内输出2对整数,自间用一个空格隔开。第一对整数是长方形框左下角的坐标,第二对整数是长方形框右上角的坐标
示例:
输入:
12 56
23 56
13 10
0 0
12 34
0 0
0 0
输出:
12 10 23 56
12 34 12 34
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<int> x;
vector<int> y;
int a=1,b=1;
int a1=1,b1=1;
int count=0;
while(a&&b )
{
cin>>a>>b;
if(a&&b)
{
a1=1;b1=1;
x.push_back(a);
y.push_back(b);
}
else
{
if(a1==0 && b1==0)
break;
a1=0;b1=0;
x.push_back(a);
y.push_back(b);
a=1;b=1;
}
}
for(int i=0;i<x.size();i++)
{
vector<int> temp_x;
vector<int> temp_y;
while(x[i]&&y[i])
{
temp_x.push_back(x[i]);
temp_y.push_back(y[i]);
i++;
}
if(temp_x.size()>0)
{
sort( temp_x.begin(), temp_x.end());
sort( temp_y.begin(), temp_y.end());
int len=temp_x.size();
cout<<temp_x[0]<<" "<<temp_y[0]<<" "<<temp_x[len-1]<<" "<<temp_y[len-1]<<endl;
}
}
return 0;
}