zoukankan      html  css  js  c++  java
  • CCF 201403-2 窗口 (STL模拟)

    问题描述
      在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域。窗口的边界上的点也属于该窗口。窗口之间有层次的区别,在多于一个窗口重叠的区域里,只会显示位于顶层的窗口里的内容。
      当你点击屏幕上一个点的时候,你就选择了处于被点击位置的最顶层窗口,并且这个窗口就会被移到所有窗口的最顶层,而剩余的窗口的层次顺序不变。如果你点击的位置不属于任何窗口,则系统会忽略你这次点击。
      现在我们希望你写一个程序模拟点击窗口的过程。
    输入格式
      输入的第一行有两个正整数,即 N 和 M。(1 ≤ N ≤ 10,1 ≤ M ≤ 10)
      接下来 N 行按照从最下层到最顶层的顺序给出 N 个窗口的位置。 每行包含四个非负整数 x1, y1, x2, y2,表示该窗口的一对顶点坐标分别为 (x1, y1) 和 (x2, y2)。保证 x1 < x2,y1 2。
      接下来 M 行每行包含两个非负整数 x, y,表示一次鼠标点击的坐标。
      题目中涉及到的所有点和矩形的顶点的 x, y 坐标分别不超过 2559 和  1439。
    输出格式
      输出包括 M 行,每一行表示一次鼠标点击的结果。如果该次鼠标点击选择了一个窗口,则输出这个窗口的编号(窗口按照输入中的顺序从 1 编号到 N);如果没有,则输出"IGNORED"(不含双引号)。
    样例输入
    3 4
    0 0 4 4
    1 1 5 5
    2 2 6 6
    1 1
    0 0
    4 4
    0 5
    样例输出
    2
    1
    1
    IGNORED
    样例说明
      第一次点击的位置同时属于第 1 和第 2 个窗口,但是由于第 2 个窗口在上面,它被选择并且被置于顶层。
      第二次点击的位置只属于第 1 个窗口,因此该次点击选择了此窗口并将其置于顶层。现在的三个窗口的层次关系与初始状态恰好相反了。
      第三次点击的位置同时属于三个窗口的范围,但是由于现在第 1 个窗口处于顶层,它被选择。
      最后点击的 (0, 5) 不属于任何窗口。
     
    析:用结构体记录id和坐标,然后用vector来存储,然后每次找到哪个窗口后,先把这个删除,然后再放到最顶层。
     
    代码如下:
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <list>
    #define frer freopen("in.txt", "r", stdin)
    #define frew freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e3 + 5;
    const int mod = 1e9 + 7;
    const int dr[] = {-1, 1, 0, 0};
    const int dc[] = {0, 0, 1, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    struct node{
        int x1, y1, x2, y2;
        int id;
    };
    vector<node> v;
    
    int main(){
        while(cin >> n >> m){
            node u;
            v.clear();
            for(int i = 0; i < n; ++i){
                cin >> u.x1 >> u.y1 >> u.x2 >> u.y2;
                u.id = i+1;
                v.push_back(u);
            }
            int x, y;
            while(m--){
                cin >> x >> y;
                bool ok = false;
                vector<node> :: iterator it = v.end();
                --it;
                while(true){
                    if(x >= it->x1 && x <= it->x2 && y >= it->y1 && y <= it->y2){
                        printf("%d
    ", it->id);
                        ok = true;
                        node u = *it;
                        v.erase(it);
                        v.push_back(u);
                        break;
                    }
                    if(it == v.begin()) break;
                    --it;
                }
                if(!ok)  puts("IGNORED");
            }
        }
        return 0;
    }
    
  • 相关阅读:
    .Net插件编程模型:MEF和MAF[转载]
    并行任务task
    wpf动画概述
    vs在线工具杂烩
    力挺8天入门wpf【转载】
    vs debug 快捷键
    Visual Studio® 2010 Web Deployment Projects站点编译生成bin同时发表插件
    EasyUI选项卡tab页面处理示例
    显示输入框只能输入的内容
    JqueryeasyUI选项卡选择判定更改内部Iframe地址
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5819029.html
Copyright © 2011-2022 走看看