• Uva11134


    #include<bits/stdc++.h>
    
    #define inf 0x3f3f3f3f
    
    const int maxn=5000;
    
    using namespace std;
    
    int n;
    
    struct rook{
            int x1,y1;
            int x2,y2;
            int id;
            int resx,resy;
            int size(){
                    return abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1 - y2);
            }
            int width(){
                    return abs(x1 - x2);
            }
            int len(){
                    return abs(y1 - y2);
            }
    }rooks[maxn+10];
    
    int flagx[maxn+10];
    
    int flagy[maxn+10];
    
    bool cmpx(rook a, rook b){
            /*if(a.width() == b.width()){
                  return a.x1 < b.x1;      
            }
            return a.width() < b.width();*/
            //刚开始想错了,这么去贪心,是错的。
                                           /* 反例
                                            * 1111
                                            * 1
                                            *  1
                                            *   1
                                            *    11
                                            */
            if(a.x2 == b.x2){
                    return a.x1 < b.x1;
            }
            return a.x2 < b.x2;
    }
    bool cmpy(rook a, rook b){
            /*if(a.len() == b.len()){
                  return a.y1 < b.y1;
            }
            return a.len() < b.len();*/
            if(a.y2 == b.y2){
                    return a.y1 < b.y1;
            }
            return a.y2 < b.y2;
    }
    bool cmp1(rook a, rook b){
            return a.id < b.id;
    }
    
    int main()
    {
            while(scanf("%d",&n)!=EOF&&n){
                    int res = 0;
                    memset(flagx, 0, sizeof(flagx));
                    memset(flagy, 0, sizeof(flagy));
                    for(int i = 0; i < n; ++i){
                            scanf("%d%d%d%d",&rooks[i].x1,&rooks[i].y1,&rooks[i].x2,&rooks[i].y2);
                            rooks[i].id = i;
                    }
                    sort(rooks, rooks + n, cmpx);
                    for(int i = 0; i < n; ++i){
                            int flag = 0;
                            for(int j = rooks[i].x1; j <= rooks[i].x2; ++j){
                                    if(!flagx[j]){
                                            flagx[j] = 1;
                                            rooks[i].resx = j;
                                            flag = 1;
                                            break;
                                    }
                            }
                            if(!flag){
                                    res = 1;
                                    break;
                            }
                    }
                    if(!res){
                            sort(rooks, rooks + n, cmpy);
                            for(int i = 0; i < n; ++i){
                                    int flag = 0;
                                    for(int j = rooks[i].y1; j <= rooks[i].y2; ++j){
                                            if(!flagy[j]){
                                                    flagy[j] = 1;
                                                    rooks[i].resy = j;
                                                    flag = 1;
                                                    break;
                                            }
                                    }
                                    if(!flag){
                                            res = 1;
                                            break;
                                    }
                            }
                    }
                    if(res){
                            printf("IMPOSSIBLE
    ");
                    } else {
                            sort(rooks, rooks + n, cmp1);
                            for(int i = 0; i < n; ++i){
                                    printf("%d %d
    ",rooks[i].resx,rooks[i].resy);
                            }
                    }
            }
        return 0;
    }
  • 相关阅读:
    Python解释器的安装 安装IDE工具 pycharm
    推荐一些基础知识,希望对大家了解python语言及计算机有一些帮助!
    Typora 技巧
    js 与或运算符 || && 妙用
    数据类型和Json格式
    从事前端开发必须要了解的CSS原理
    CSS浏览器兼容
    用jQuery Mobile创建Web App
    让你的网站变成响应式的3个简单步骤
    CSS BFC hasLayout模型
  • 原文地址:https://www.cnblogs.com/GeniusYang/p/6695368.html
Copyright © 2020-2023  润新知