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=;i<=n;i++)scanf("%d%d",&p[i].a,&p[i].b);
sort(p+,p+n+,cmp);
d[]=p[].a;
int len=;
for(int i=;i<=n;i++){
if(d[len]>=p[i].a)d[++len]=p[i].a;
else{
int l=,r=len,mid,ans=-;
while(l<=r){
mid=(l+r)>>;
if(d[mid]<p[i].a){
ans=mid;
r=mid-;
}
else l=mid+;
}
d[ans]=p[i].a;
}
}
printf("%d\n",len);
return ;
}
 

CS Round#50 D min-races的更多相关文章

  1. DP BestCoder Round #50 (div.2) 1003 The mook jong

    题目传送门 /* DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp ...

  2. 简单几何(水)BestCoder Round #50 (div.2) 1002 Run

    题目传送门 /* 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 */ /***** ...

  3. CSA Round #50 (Div. 2 only) Min Swaps(模拟)

    传送门 题意 给出一个排列,定义\(value为\sum_{i=1}^{n-1}abs(f[i+1]-f[i])\) \(swap(a[i],a[j])(i≠j)为一次交换\),询问最少的交换次数使得 ...

  4. Educational Codeforces Round 50

    1036A - Function Height    20180907 \(ans=\left \lceil \frac{k}{n} \right \rceil\) #include<bits/ ...

  5. Round #427 A. Key races(Div.2)

      time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  6. Cs Round#54 E Late Edges

    题意:给定一个无向图,你从结点1开始走,每经过一条边需要1的时间,每条边都有一个开放时间,只有当目前所用的时间大于等于开放时间时,这条边才可以被经过.每一单位时间你都必须经过一条边,问最快什么时候可以 ...

  7. CS Round#53 C Histogram Partition

    题意:给定一个数组A,以及一个初始值全为0的空数组B,每次可以对数组B的任意一个区间内的所有数+x,问至少几次操作能把B数组变成A数组 NOIP原题(积木大赛)升级版,话说CS怎么那么多跟NOIP原题 ...

  8. 【CS Round #36 (Div. 2 only) A】Bicycle Rental

    [题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...

  9. 【CS Round #39 (Div. 2 only) D】Seven-segment Display

    [Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...

随机推荐

  1. windy数(数位DP)

    windy数Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:165888KB     64bit I ...

  2. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution

    B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit ...

  3. eclipse中删除多余的tomcat server

    在eclipse菜单中选择Window--Show View--Server--Servers,打开这个服务窗口,将多余的服务删除即可. 如果每次启动中太卡没反应,那就是服务没选择好,或是端口冲突的原 ...

  4. SVN服务迁移备份操作步骤

    SVN服务备份操作步骤 1.准备源服务器和目标服务器 源服务器:192.168.1.250 目标服务器:192.168.1.251 root/rootroot 2.对目标服务器(251)装SVN服务器 ...

  5. ASP.NET Core集成现有系统认证

    我们现在大多数转向ASP.NET Core来使用开发的团队,应该都不是从0开始搭建系统,而是老的业务系统已经在运行,ASP.NET Core用来开发新模块.那么解决用户认证的问题,成为我们的第一个拦路 ...

  6. 一、VueJs 填坑日记之基础概念知识解释

    概述在最开始听说vuejs这个词是在2016年,当时天真的认为自己是个后端开发工程师不需要学习太多的前端知识,不过紧接着在2017年在公司就用到了vuejs.对于初学者(尤其是干后端的初学者)来说,刚 ...

  7. 解决ajax的parsererror错误的终极办法(后台传给前台的数据json问题)

    解决ajax的parsererror错误的终极办法(后台传给前台的数据json问题) 出现这个问题的原因是因为后台传给前台的数据出现了问题,ajax对于json的格式特别的严格 下面是会出现这个问题的 ...

  8. ROS wiki 学习(1)创建程序包时遇到的rosdep update出错

    1. 使用turtlebot官网的ubuntu14.04走ROS维基时,在创建程序包后出现错误. 按照提示执行之后,出现以下错误. 搜寻度娘,几经波折后,终于解决.解决过程如下: 首先删除默认文件20 ...

  9. Python异步处理

    回调函数是实现异步操作的常用手法 1.callback版本的示例,其中framework调用logic,在完成某些操作或者接收到信号后,用callback返回异步结果 #!/usr/bin/env p ...

  10. markdown使用小结

    初学时,对不太熟悉的markdown语法,有个简单记录 公式 公式一般用Latex书写,在线Latex编辑器可以使用,有以下几种方法供选择 有然后保存为图片gif格式,使用img标签进行引用. 使用G ...