• CS Round#50 D min-races


    Min Races

    Time limit: 1000 ms
    Memory limit: 256 MB

     

    In a racing championship there are N racing drivers. The drivers are divided in K classes.

    After a race, a driver is declared a winner if all the drivers that finish in front of him are from better classes (with smaller indices than his own).

    As the main organiser of the championship, you can choose for each race which drivers are allowed to participate. Find the minimum number of races needed such that every driver is a winner at least once.

    Standard input

    The first line contains 2 integers N and K.

    Each of the next N lines contains 2 integers a_i and b_i. The first integer a_i​​ represents the class of driver i, while b_i is his place in a race with all the N drivers.

    Standard output

    Print the answer on the first line.

    Constraints and notes

    • 1≤KN105​​ 
    • There will be at least one driver from each class
    • The values bb will be a permutation from 1 to N. 
     
    题意:N人进行赛车比赛,其中他们被分为K组。在一场比赛中,如果一个人没有被组别小于他的人排名高于他,他就被认为是获胜。已知每个人能力的排名,求至少要进行多少场比赛才能让每个人至少获胜一场?
     
    对bi进行排序后,不难发现这是一个求最小上升子序列覆盖的问题。对此有一个定理:最小覆盖数=最长不上升子序列长度。(最小连覆盖=最长反链)由是排序后跑一边LIS即可。‘
     
    #include<bits/stdc++.h>
    using namespace std;
    #define MAXN 100000+10
    struct per{int a,b;}p[MAXN];
    int n,k,d[MAXN];
    bool cmp(per x,per y){return x.b<y.b;}
    int main(){
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)scanf("%d%d",&p[i].a,&p[i].b);
        sort(p+1,p+n+1,cmp);
        d[1]=p[1].a;
        int len=1;
        for(int i=2;i<=n;i++){
            if(d[len]>=p[i].a)d[++len]=p[i].a;
            else{
                int l=1,r=len,mid,ans=-1;
                while(l<=r){
                    mid=(l+r)>>1;
                    if(d[mid]<p[i].a){
                        ans=mid;
                        r=mid-1;
                    }
                    else l=mid+1;
                }
                d[ans]=p[i].a;
            }
        }
        printf("%d
    ",len);
        return 0;
    }
     
  • 相关阅读:
    基于YIIFRAMEWORK框架开发学习(一)
    Android学习系列(24)App代码规范之使用CheckStyle
    64为操作系统,64位IIS,运行32位应用程序的问题
    IE下设置网页为 首页,收藏
    部分.net 目录
    强大的ldd
    (原创)初试Robotium
    在solaris上安装iperf
    (原创)LoadRunner 中 调用dll
    (原创)学习NotesList(Robotium自带的例子)
  • 原文地址:https://www.cnblogs.com/NINGLONG/p/7606850.html
Copyright © 2020-2023  润新知