hdu 1859 最小长方形

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
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main()
{
    int x,y;
    while(cin>>x>>y)
    {
        if(x==0&&y==0) break;
        int x1,y1,x2,y2;
        x1=x;y1=y;
        x2=x;y2=y;
        while(cin>>x>>y)
        {
            if(x==0&&y==0) break;
            if(x<=x1)
            x1=x;
            if(y<=y1)
            y1=y;
            if(x>=x2)
            x2=x;
            if(y>=y2)
            y2=y;
        }
        cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    }
    return 0;
}
时间: 2024-08-24 19:50:36

hdu 1859 最小长方形的相关文章

杭电 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坐标轴,点落在边上也算是被框在内.

hdoj 1859 最小长方形

最小长方形 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8339    Accepted Submission(s): 4476 Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内. I

hdu 3657 最小割的活用 / 奇偶方格取数类经典题 /最小割

题意:方格取数,如果取了相邻的数,那么要付出一定代价.(代价为2*(X&Y))(开始用费用流,敲升级版3820,跪...) 建图:  对于相邻问题,经典方法:奇偶建立二分图.对于相邻两点连边2*(X&Y),源->X连边,Y->汇连边,权值w为点权. ans=总点权-最小割:如果割边是源->X,表示x不要选(是割边,必然价值在路径上最小),若割边是Y-汇点,同理:若割边是X->Y,则表示选Y点且选X点, 割为w( 2*(X&Y) ). 自己的确还没有理解其本质

HDU 4160 最小路径覆盖

Dolls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1040    Accepted Submission(s): 496 Problem Description Do you remember the box of Matryoshka dolls last week? Adam just got another box of

HDU 1350 最小路径覆盖

Taxi Cab Scheme Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 707    Accepted Submission(s): 336 Problem Description Running a taxi station is not all that simple. Apart from the obvious dem

String Problem hdu 3374 最小表示法加KMP的next数组

String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1492    Accepted Submission(s): 662 Problem Description Give you a string with length N, you can generate N strings by left shifts.

hdu 4966 最小树形图

将每门课等级拆成0,1,2,3...a[i]个点,对每个等级大于0的点向它低一级连边,权值为0[意思是,若修了level k,则level(0~k)都当做修了] 将输入的边建边,权值为money[i]. 建立根节点,向每个level 0的点连边,权值为0[因为初始level 0的都修了] 由于题目要求每门课都必须达到最大level,也就是对应图中根节点能到达所有点,问题就变成了求无向图的最小生成树. #include<iostream> #include<cstdio> #incl

HDU 1150 最小点覆盖数

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5614    Accepted Submission(s): 2804 Problem Description As we all know, machine scheduling is a very classical problem in comput

hdu 2516 最小费用最大流

原来这个代码超时 #include<stdio.h> #include<queue> #include<string.h> using namespace std; #define N 200 #define inf 0x3fffffff int cap[N][N]; int fee[N][N]; int s,t,sum,pre[N]; int spfa() { queue<int>q; int dis[N],visit[N],u,i; memset(pre