zoukankan      html  css  js  c++  java
  • 2014 Benelux Algorithm Programming Contest (BAPC 14)E

    题目链接:https://vjudge.net/contest/187496#problem/E

    E Excellent Engineers

    You are working for an agency that selects the best software engineers from Belgium, the Netherlands and Luxembourg for employment at various international companies. Given the very large number of excellent software engineers these countries have to offer, the agency has charged you to develop a tool that quickly selects the best candidates available from the agency’s files. Before a software engineer is included in the agency’s files, he has to undergo extensive testing. Based on these tests, all software engineers are ranked on three essential skills: communication skills, programming skills, and algorithmic knowledge. The software engineer with rank one in the category algorithmic knowledge is the best algorithmic expert in the files, with rank two the second best, etcetera. For potential customers, your tool needs to process the agency’s files and produce a shortlist of the potentially most interesting candidates. A software engineer is a potential candidate that is to be put on this shortlist if there is no other software engineer in the files that scores better on all three skills. That is, an engineer is to be put on the shortlist if there is no other software engineer that has better communication skills, better programming skills, and more algorithmic knowledge.

    Input On the first line one positive number: the number of test cases, at most 100. After that per test case: • one line with a single integer n (1 ≤ n ≤ 100 000): the number of software engineers in the agency’s files. • n lines, each with three space-separated integers r1, r2 and r3 (1 ≤ r1, r2, r3 ≤ n): the rank of each software engineer from the files with respect to his communication skills, programming skills and algorithmic knowledge, respectively. For each skill s and each rank x between 1 and n, there is exactly one engineer with rs = x. 10 Problem E: Excellent Engineers Output Per test case: • one line with a single integer: the number of candidates on the shortlist.

    Sample in- and output

    Input        Output

    3 3               1

    2 3 2            3

    3 2 3             7

    1 1 1

    3

    1 2 3

    2 3 1

    3 1 2

    10

    1 7 10

    3 9 7

    2 2 9

    5 10 8

    4 3 5

    7 5 2

    6 1 3

    9 6 6

    8 4 4

    10 8 1

    题意:给出N,个人在三个方面(a,b,c)的名次,问你没有一个人名次在三个方面都比某个人好的个数。

    题解:先用结构体按a从小到大排序,然后建一个线段树,在b位置的值对应c,先把线段树初始化为inf,然后按结构排好的顺序每次对b位置的值更新为c,判断某个人是否合适只要看线段树

    从1~b的最小值是否小于自己的C值

    复杂度为(N*log(N))

    #include<bits/stdc++.h>
    #define pb push_back
    #define ll long long
    #define PI 3.14159265
    using namespace std;
    const int maxn=1e5+5;
    const int inf=0x3f3f3f3f;
    int t,n;
    int sd[maxn];
    int tree[maxn<<2];
    struct node
    {
        int a,b,c;
        bool operator<(const node d)const
        {
            return a<d.a;
        }
    }st[maxn];
    void update(int loc,int num,int l,int r,int rt)
    {
        if(l==r)
        {    
            tree[rt]=num;
            return ;
         }
         int mid=(l+r)>>1;
         if(loc>mid)update(loc,num,mid+1,r,rt<<1|1);
         else update(loc,num,l,mid,rt<<1);
        tree[rt]=min(tree[rt<<1],tree[rt<<1|1]); 
        return; 
    }
    int query(int L,int R,int l,int r,int rt)
    {
    //    cout<<L<<' '<<R<<" "<<l<<" "<<r<<" "<<rt<<endl; 
        if(L<=l&&r<=R)
        {
        
            return tree[rt]; 
        } 
        int m=(l+r)>>1;
        int ans=inf; 
        if(R>m)
            ans=min(ans,query(L,R,m+1,r,rt<<1|1));
        if(L<=m)
            ans=min(ans,query(L,R,l,m,rt<<1));
        return ans;  
    } 
    int main()
    {    
        std::ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin>>t;
        while(t--)
        {
            cin>>n;
            for(int i=0;i<n;i++)
            {
                cin>>st[i].a>>st[i].b>>st[i].c; 
            }
            sort(st,st+n);int cnt=0;
            memset(tree,inf,sizeof(tree));
            update(st[0].b,st[0].c,1,n,1);
            for(int i=1;i<n;i++)
            {
                if(st[i].b==1)
                {
                    update(st[i].b,st[i].c,1,n,1);
                    continue;
                }
                int tmp=query(1,st[i].b-1,1,n,1);
            //    cout<<tmp<<endl;
                update(st[i].b,st[i].c,1,n,1);
                if(tmp<st[i].c)cnt++; 
             }
             cout<<n-cnt<<endl; 
        }
        
        return 0;
    }
  • 相关阅读:
    hdu 1551 恶心的卡精度题
    ubuntu下升级firefox
    清理windows垃圾
    hdu 1575 矩阵快速幂
    右键菜单中添加用记事本打开(转)
    hdu 1525 博弈
    PHP字符串函数(转)
    笔试注意事项
    .NET 2.0面向对象编程揭秘 继承
    李开复:21世纪7种人才最抢手
  • 原文地址:https://www.cnblogs.com/lhclqslove/p/7620316.html
Copyright © 2011-2022 走看看