美文网首页
poj1083 偏序问题

poj1083 偏序问题

作者: 暖昼氤氲 | 来源:发表于2019-11-04 16:46 被阅读0次
    /*
    Time:2019.11.4
    Author: Goven
    type:偏序问题 
    err: 1.输入可能(14, 13) 
        2.房间是对着的,不是一字排开的,所以(2,3) (3,4)是不能同时走的 
    ref: 类似1065:https://blog.csdn.net/AC_hell/article/details/51416840
    */
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    struct Node {
        int s, e;
    };
    
    Node a[205];
    bool visit[205];
    bool cmp(const Node &x, const Node &y) {
        if (x.s != y.s) return x.s < y.s;
        return x.e < y.e;
    }
    
    int main()
    {
        int t, n, s, e;
        cin >> t;
        while (t--) {
            cin >> n;
            for (int i = 0; i < n; i++) {
                cin >> s >> e;
                s = (s + 1) / 2;//err2
                e = (e + 1) / 2; 
                a[i].e = max(s, e);//err1
                a[i].s = min(s, e);
            }
            sort(a, a + n, cmp);
            memset(visit, 0, sizeof(visit));
            int begin, flag, cnt = 0, sum = 0;
            while (cnt < n) {
                flag = 0; begin = -1;
                for (int j = 0; j < n; j++) {
                    if (visit[j] == false && begin < a[j].s) {
                        begin = a[j].e;
                        visit[j] = true;
                        flag = 1;
                    }
                }
                if (flag) sum++;
                cnt++;
            }
            cout << sum * 10 << endl;
        }
        return 0;
    }
    
    
    
    

    相关文章

      网友评论

          本文标题:poj1083 偏序问题

          本文链接:https://www.haomeiwen.com/subject/llmdbctx.html