CS Round50D 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≤K≤N≤10?5??
  • 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\n",len);
    return 0;
}
时间: 2024-07-29 14:05:08

CS Round50D min-races的相关文章

CS Round #50 Min Races(nlogn级别的LDS)

题目链接:点——点 题意:n个比赛者,每个比赛者都有自己的班级(似乎是这样翻译,就像实力至上的教室那里面的A,B,C班一样,1班最强...),和自己在n名选手中能排到的名次. 如果名次排在自己前面的选手的班级更厉害(比如1班就比2班强,废话...),那么这个选手自己心里就觉得自己赢了. 题解:看了好久的题目才理解它要问什么.简单来说,先按照名次排个序,然后去取最长递增序列,把每个人都遍历过,然后算出有几条就可以了.(这个其实反过来就是求最长递减子序列) 给出的n达到1e5,所以肯定不能直接dp,

Bootstrap中的 Typeahead 组件

Bootstrap 中的 Typeahead 组件其实就是嵌入到其中的typeahead.js插件,可以完成输入框的自动匹配功能,在通过一些人工的调整基本可以胜任所有的匹配功能和场景,下面介绍下简单的使用思路: 首先,最简单的使用方式,就是直接在标记中声明,通过 data-provide="typeahead" 来声明这是一个 typeahead 组件,通过 data-source= 来提供数据.当然了,你还必须提供 bootstrap-typeahead.js 脚本. 如: <

hdu 4366 Successor - CDQ分治 - 线段树 - 树分块

Sean owns a company and he is the BOSS.The other Staff has one Superior.every staff has a loyalty and ability.Some times Sean will fire one staff.Then one of the fired man’s Subordinates will replace him whose ability is higher than him and has the h

【解题报告】Math

= =本来昨天就该发的,只是断网……. MATH  [题目描述] 小 x正在做他的数学作业,可是作业实在太难了.题目是这样的: 1.给定一个含有N个数的数列 V. 2.你可以从数列中恰好移除 K个数,定义移除后的数列为 V’. 3.定义M为V’中任意两个数的差的最大值,m为 V’中任意两个数的差的最小值. 4.请你选择删去的K 个数,使得M+m最小. 小 x的数学十分之差,于是他只能向你求助了.  [输入] 第一行两个整数 N和K. 第二行N个整数Vi.  [输出] 一行一个整数,为最小的M+m

i18next.min.js

// i18next, v1.7.7// Copyright (c)2014 Jan Mühlemann (jamuhl).// Distributed under MIT license// http://i18next.com!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)

MVC Min Blog(1)- 开发环境

一直都有接触asp.net mvc,希望自己借此次机会把Blog搭起来的同时能够更深入地学习相关知识. ①新建 打开VS2012,新建ASP.Net MVC 4项目,接着选择“空”模板(因为不想用自带的一些模板,所以选择了“空”模板,如果想“基本”,则会默认帮我们添加一些基本的页面和代码) ②Entity Framework 既然用到了MVC,自然少不了Entity Framework.使用EF时,我们可以采用三种方式: Database First, Model First, and Code

已知从BUF开始存放了10个字类型有符号数据,编程求出这10个数中的最大数和最小数(将最大数存入MAX字单元、最小数存入MIN字单元),并将其以10进制数的形式在屏幕上显示出来。

data segment pmax db 0dh,0ah , 'MAX : ','$' pmin db 0dh,0ah , 'MIN : ','$' buf dw 48,-2 ,49,50,30,-78,-88,-60,-1,48 max dw 99 min dw 20 data ends code segment assume cs:code , ds:data main proc far start: mov ax,data mov ds,ax call compare lea dx,pma

Codeforce 835A - Key races

Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The secon

【VIJOS】P1401复制CS

背景 SQ CLASS的机房里流行玩CS,几乎每台电脑上的D盘都有(每台电脑只有C盘和D盘,C盘有硬盘保护卡保护).SQ非常恼火,因为这严重影响了教学秩序. 描述 有一天,机房所有机器的D盘都被物理格式化了,也就是说CS全都没有了:而且局域网也被关闭了,也就是说网上邻居看不到其他机器了. 但是,道高一尺,魔高一丈.一天,一个同学不知道使用了什么方法,在一台计算机的D盘上安装了CS.由于局域网不通了,其他同学没有办法通过网络复制.但是,现在有k根并口线,可以用来复制.一根并口线可以连接两台计算机: