题解 | #最小长方形#

最小长方形

https://www.nowcoder.com/practice/dc6a75a15d1948edafa6d63bc8fc2368

#include <iostream>
#include <algorithm>
using namespace std;

struct dot{
    long x;
    long y;
};

dot dots[10000*10000];

int main() {
    int x, y,count = 0;
    while (cin >> x >> y) { // 注意 while 处理多个 case
        if(count == 0&&x == 0&&y == 0) break;
        else{
            if(x!=0||y!=0){
               dots[count].x = x;
               dots[count].y = y;
               count++;
            }else if(x==0&&y==0){
               long minX = 10000000000,minY = 10000000000,maxX = 0,maxY = 0;
               for(int i = 0; i < count;i++){
                   if(dots[i].x < minX) minX = dots[i].x;
                   if(dots[i].y < minY) minY = dots[i].y;
                   if(dots[i].x > maxX) maxX = dots[i].x;
                   if(dots[i].y > maxY) maxY = dots[i].y;
                }
                cout << minX << " "<< minY << " "<< maxX << " "<< maxY << " "<< endl;
                count = 0;
        }
        }
        
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 12:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务