• 201403-2 窗口


    实现

    
    #include <cstdio>
    #include <vector>
    #include <algorithm>
    
    class window {
    
    public:  
        int x1,x2;
        int y1,y2;
        int id;
    
        window() {}
        window(int x1,int y1, int x2, int y2, int id) :
        x1(x1), y1(y1), x2(x2), y2(y2), id(id) {}
    
        bool inRange(int x, int y) {
            return (x1 <= x && x <= x2) && (y1 <= y && y <= y2);
        }
    
        int get_id() {
            return this->id;
        }
    
    };
    
    class Window_interaction {
    
    public:
        std::vector<window> windows;
    
        int id;
    
        Window_interaction() {
            id = 1;
        }
    
        void add_windows (int x1, int y1, int x2, int y2) {
            window one_window = window(x1,y1,x2,y2,this->id);
            this->id++;
            windows.insert(windows.begin(),one_window);
        }
    
        int response_click(int x, int y) {
            int response_id = 0;
            window click_window;
    
            std::vector<window>::iterator ite = windows.begin();
            for ( ;ite != windows.end(); ++ite) {
                if (ite->inRange(x,y)) {
                    response_id = ite->id;
                    click_window.x1 = ite->x1;
                    click_window.x2 = ite->x2;
                    click_window.y1 = ite->y1;
                    click_window.y2 = ite->y2;
                    click_window.id = ite->id;
                    windows.erase(ite);
                    break;
                }
            }
    
            if (response_id) {
                windows.insert(windows.begin(),click_window);
            }
            
            return response_id;
        }
    
    };
    
    int main() {
    
        int windows_num, click_num;
        Window_interaction win_interact;
        scanf("%d%d",&windows_num, &click_num);
    
        for(int i = 0;i < windows_num;++i) {
            int x1,y1,x2,y2;
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            win_interact.add_windows(x1,y1,x2,y2);
        }
    
        for (int i = 0;i < click_num;++i) {
            int x, y;
            scanf("%d%d",&x,&y);
    
            int response_id = win_interact.response_click(x,y);
            if (response_id) {
                printf("%d
    ",response_id);
            } else {
                printf("IGNORED
    ");
            }
        }
    
    
    }
    
    
    
  • 相关阅读:
    快速排序就这么简单
    Shiro入门这篇就够了【Shiro的基础知识、回顾URL拦截】
    SpringDataJPA入门就这么简单
    递归就这么简单
    SpringBoot就是这么简单
    Activiti就是这么简单
    Lucene就是这么简单
    过来人告诉你,去工作前最好还是学学Git
    给女朋友讲解什么是Git
    我终于看懂了HBase,太不容易了...
  • 原文地址:https://www.cnblogs.com/amonqsq/p/13547815.html
Copyright © 2020-2023  润新知