GYM 100820 G.Racing Gems（LIS）

Description

Input

Output

Sample Input
5 1 10 10
8 8
5 1
4 6
4 7
7 9
Sample Output
3
Solution

Code

``#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 1e12#define maxn 111111int n,r,w,h;struct node{    ll a,b;    bool operator<(const node&c)const    {        if(a!=c.a)return a<c.a;        return b<c.b;    }}p[maxn];ll a[maxn],dp[maxn];int LIS(ll a[])//求序列a的(非严格)最长上升子序列 {    for(int i=1;i<n;i++)dp[i]=INF;    dp[0]=a[0];    int len=1;    for(int i=1;i<n;i++)    {        if(a[i]>=dp[len-1])dp[len++]=a[i];        else dp[upper_bound(dp,dp+n,a[i])-dp]=a[i];    }    return len;}int main(){    while(~scanf("%d%d%d%d",&n,&r,&w,&h))    {        for(int i=0;i<n;i++)        {            ll x,y;            scanf("%I64d%I64d",&x,&y);            p[i].a=1ll*r*x+y,p[i].b=1ll*r*(w-x)+y;        }        sort(p,p+n);        for(int i=0;i<n;i++)a[i]=p[i].b;        printf("%d\n",LIS(a));    }    return 0;}``

0 0