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. RSA加密算法验证(C#实现)

    RSA算法简单原理介绍(节选于网络) 假设Alice想要通过一个不可靠的媒体接收Bob的一条私人讯息.她可以用以下的方式来产生一个公钥和一个私钥: 随意选择两个大的质数p和q,p不等于q,计算N=pq ...

  2. Node.js CVE-2017-1484复现(详细步骤)

    0x00 前言 早上看Sec-news安全文摘的时候,发现腾讯安全应急响应中心发表了一篇文章,Node.js CVE-2017-14849 漏洞分析(https://security.tencent. ...

  3. Pandas常用函数入门

    一.Pandas Python Data Analysis Library或Pandas是基于NumPy的一种工具,该工具是为了解决数据分析任务而创建的.Pandas纳入了大量库和一些标准的数据模型, ...

  4. mac中利用brew实现多版本php共存以及任意切换

    1.安装brew 参考链接:https://brew.sh/index_zh-cn.html 2.安装php56 brew install homebrew/php/php56 3.配置php56 因 ...

  5. Java build path && Deployment assembly && 编译路径 && 发布路径

    java build path java源文件,编译后,输出的路径,默认值为: *此时的源码文件夹在 /src deployment assembly 系统发布路径设置,将完成(或未完成)的项目对应的 ...

  6. Python之多进程篇

    Process 创建子进程执行指定的函数 >>> from multiprocessing import Process,current_process >>> & ...

  7. Eclipse中代码整体左移,右移快捷键

    1.向右:将要移动的代码选中,然后按TAB键2.向左:将要移动的代码选中,然后按SHIFT+TAB键

  8. Python 爬虫练习(三) 利用百度进行子域名收集

    不多介绍了,千篇一律的正则匹配..... import requests import re head = {'User-Agent': \ 'Mozilla/5.0 (Windows NT 6.3; ...

  9. Redis+Tomcat+Nginx集群实现Session共享,Tomcat Session共享

    Redis+Tomcat+Nginx集群实现Session共享,Tomcat Session共享 ============================= 蕃薯耀 2017年11月27日 http: ...

  10. RecyclerView.ItemDecoration

    decoration 英文意思: 英[ˌdekəˈreɪʃn] 美[ˌdɛkəˈreʃən] n. 装饰品; 装饰,装潢; 装饰图案,装饰风格; 奖章; [例句]The decoration and ...