杭电 HDU ACM 1859 最小长方形

最小长方形

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 8100    Accepted Submission(s): 4394

Problem Description

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

Input

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

Output

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

Sample Input

12 56
23 56
13 10
0 0
12 34
0 0
0 0

Sample Output

12 10 23 56
12 34 12 34

Source

浙大计算机研究生复试上机考试-2007年

大半夜的这个题可气人了 ,以前循环喜欢这样写 while(cin>>x>>y,x+y)可这次非得这样写while((cin>>x>>y)&&(x||y));妈的蛋  浪费太多时间发现她,就是不知道为啥。

以前也没错过啊!

AC一:

#include<iostream>
#include<algorithm>
using namespace std;
int ls[100000], gq[100000];
int main()
{
int i=0;
while((cin>>ls[i]>>gq[i])&&(ls[i]||gq[i]))
{
	 i++;
	while((cin>>ls[i]>>gq[i])&&(ls[i]||gq[i]))
	i++;
    sort(ls,ls+i);
	 sort(gq,gq+i);
	 cout<<ls[0]<<" "<<gq[0]<<" "<<ls[i-1]<<" "<<gq[i-1]<<endl;
	 i=0;

}
return 0;
}

AC二:

#include<iostream>
#include<algorithm>
using namespace std;
struct co
{
	int x;
	int y;
}per[10000];
bool cmp1(co a,co b)
{
	return a.x<b.x;
}
bool cmp2(co a,co b)
{
	return a.y<b.y;
}

int main()
{
	int x,y,i=0;
while(1)
{
	i=0;
while((cin>>per[i].x>>per[i].y)&&(per[i].x||per[i].y))
	{i++;}
     if(!i)
	 {

		 break;
	 }
	sort(per,per+i,cmp1);
	int k=per[0].x;int m=per[i-1].x;
	sort(per,per+i,cmp2);
	int l=per[0].y;int u=per[i-1].y;
	cout<<k<<" "<<l<<" "<<m<<" "<<u<<endl;
}
return 0;
}
时间: 2024-12-29 18:04:26

杭电 HDU ACM 1859 最小长方形的相关文章

杭电 HDU ACM 1025 Constructing Roads In JGShining&#39;s Kingdom

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17732    Accepted Submission(s): 5023 Problem Description JGShining's kingdom consists of 2n(n is no mo

杭电 HDU ACM 1397 Goldbach&#39;s Conjecture

Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4976    Accepted Submission(s): 1901 Problem Description Goldbach's Conjecture: For any even number n greater than or equal

杭电 HDU ACM 5186 zhx&#39;s submissions

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1892    Accepted Submission(s): 507 Problem Description As one of the most powerful brushes, zhx submits a lot of code on many

杭电HDU ACM Uncle Tom&#39;s Inherited Land*(二分图匹配 建模)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2496    Accepted Submission(s): 1028 Special Judge Problem Description Your old uncle Tom inherited a piece of land f

杭电 HDU ACM 1407 测试你是否和LTC水平一样高

测试你是否和LTC水平一样高 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14276    Accepted Submission(s): 4701 Problem Description 大家提到LTC都佩服的不行,不过,如果竞赛只有这一个题目,我敢保证你和他绝对在一个水平线上! 你的任务是: 计算方程x^2+y^2+z^2= n

杭电 HDU ACM 圆桌会议

圆桌会议 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3356    Accepted Submission(s): 2351 Problem Description HDU ACM集训队的队员在暑假集训时经常要讨论自己在做题中遇到的问题.每当面临自己解决不了的问题时,他们就会围坐在一张圆形的桌子旁进行交流,经过大家的讨论后一般没有

杭电 HDU ACM 1046 Tempter of the Bone

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 83458    Accepted Submission(s): 22740 Problem Description The doggie found a bone in an ancient maze, which fascinated him a

杭电 HDU ACM 1496 Equations

Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6065    Accepted Submission(s): 2455 Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a,

杭电 HDU ACM 1283 最简单的计算机

最简单的计算机 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5238    Accepted Submission(s): 2967 Problem Description 一个名叫是PigHeadThree的研究组织设计了一台实验用的计算机,命名为PpMm.PpMm只能执行简单的六种命令A,B,C,D,E,F:只有二个内存M1,M