ZOJ-2099 矩形边界

2099:给出一段折线,求一个能包住次折线的最小矩形。

思路:找出最左最右的x值,最上最下的y值即可。
由于整数范围内都合法,初始时有些麻烦。因此设了一个变量代表第一次赋值。


#include<stdio.h>
#include<iostream>
using namespace std;


int main()
{
int southwest_x;
int southwest_y;
int northeast_x;
int northeast_y;
int x;
int y;
bool isend=false;
bool isfirst;

while(!isend)
{
southwest_x=0;
southwest_y=0;
northeast_x=0;
northeast_y=0;
isfirst=true;

while(1)
{
cin>>x;
cin>>y;
if(x==0&&y==0)
{
if(!(southwest_x||southwest_y||northeast_x||northeast_y))
{
isend=true;
break;
}
else
break;
}

if(isfirst)
{
southwest_x = x;
southwest_y = y;
northeast_x = x;
northeast_y = y;
isfirst=false;
}

if(x<=southwest_x)
southwest_x = x;

if(y<=southwest_y)
southwest_y = y;

if(x>=northeast_x)
northeast_x=x;

if(y>=northeast_y)
northeast_y=y;

}
if(!isend)
cout<<southwest_x<<" "<<southwest_y<<" "<<northeast_x<<" "<<northeast_y<<endl;
}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值