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

题目链接:点——点

题意:n个比赛者,每个比赛者都有自己的班级(似乎是这样翻译,就像实力至上的教室那里面的A,B,C班一样,1班最强...),和自己在n名选手中能排到的名次。

如果名次排在自己前面的选手的班级更厉害(比如1班就比2班强,废话...),那么这个选手自己心里就觉得自己赢了。

题解:看了好久的题目才理解它要问什么。简单来说,先按照名次排个序,然后去取最长递增序列,把每个人都遍历过,然后算出有几条就可以了。(这个其实反过来就是求最长递减子序列)

给出的n达到1e5,所以肯定不能直接dp,要用到nlogn的LDS。

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4
 5 const int N=1e5+10;
 6 struct TnT{
 7     int a,b;
 8 }T[N];
 9
10 int A[N],B[N];
11
12 bool cmp(TnT x,TnT y){
13     return x.b<y.b;
14 }
15
16 int binsearch(int low,int high,int num){
17     while(low<=high){
18         int mid=(low+high)/2;
19         if(B[mid]>=num) low=mid+1;
20         else high=mid-1;
21     }
22     return low;
23 }
24
25 int dp(int n){
26     B[1]=A[1];
27     int len=1;
28     for(int i=2;i<=n;i++){
29         if(A[i]<=B[len]) {len++;B[len]=A[i];}
30         else{
31             int pos=binsearch(1,n,A[i]);
32             B[pos]=A[i];
33         }
34     }
35     return len;
36 }
37
38 int main(){
39     int n,k;
40     cin>>n>>k;
41     for(int i=1;i<=n;i++) cin>>T[i].a>>T[i].b;
42     sort(T+1,T+1+n,cmp);
43     for(int i=1;i<=n;i++) A[i]=T[i].a;
44     cout<<dp(n)<<endl;
45     return 0;
46 }
时间: 2024-07-31 23:59:25

CS Round #50 Min Races(nlogn级别的LDS)的相关文章

BestCoder Round #50 (div.2)

题目传送:BestCoder Round #50 (div.2) BC感觉越做越无语了 1001.Distribution money AC代码: #include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <bitset> #

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

题目传送门 1 /* 2 DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: 3 dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp[i][0] = dp[i-1][1] + dp[i-1][0]; 4 比赛时二维dp写搓了,主要是边界情况的判断出错,比如dp[3][1] = 1,因为第3块放了木桩,其他地方不能再放,dp[3][0]同理 5 解释一下dp[i][1]的三种情况,可能是前面相隔2个放的方案或者是不放的

计算几何(水)BestCoder Round #50 (div.2) 1002 Run

题目传送门 1 /* 2 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 3 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-8 19:54:14 8 * File Name :B.cpp 9 ************

BestCoder Round #50 (div.2) HDU 5365 Run(简单几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5365 题面:(严重吐槽,看着真不舒服,还是改一下吧) Run Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 549    Accepted Submission(s): 245 Problem Description AFA is a g

BestCoder Round #50 (div.1) 1001 Distribution money (HDU OJ 5364)

题目:Click here 题意:bestcoder上面有中文题目 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <string> 7 #include <climits> 8 #include <vector> 9 #incl

Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码

A题链接:https://codeforces.com/contest/1036/problem/A A题AC代码: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <math.h> 5 #include <malloc.h> 6 #include <stdbool.h> 7 #include <ctype.h> 8 9

Codeforces Edu Round 50 A-D

A. Function Height 由于只能提升\(x\)为奇数的点,每个三角形的底一定为\(2\), 则要求我们求: \(2 * (h_1 + h_2 + - + h_n) / 2 = k\),使\(max(h_1, h_2-h_n)\)最小. 则应使每个\(h\)平摊重量,答案即为\(\lceil n/k \rceil\). #include <cstdio> #include <iostream> #include <cmath> typedef long lo

BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定

题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #define power(x) ((x)*(x))

CS Round#49 C Max Substring

Max Substring Time limit: 1000 msMemory limit: 256 MB You are given a string S. Find a string T that has the most number of occurrences as a substring in S. If the solution is not unique, you should find the one with maximum length. If the solution i